I am facing a issue to access my shiny module's dynamic input value from slider in the main shiny server function.
In the following code from SelectInput when metric2 is selected, I should be able to see a slider with a specific range and a default. That works perfectly. But the value from the slider is expected to be shown as TextOutput in the main shiny server function, which is failing.
main shiny file:
library(shiny)
source("modules/showLowHighSliders.R")
ui <- fluidPage(
fluidRow(
column(
3,
selectizeInput(
inputId = "metricID",
selected = NULL,
multiple = TRUE,
label = "Select a metric",
choices = list(
Type1 = c("metric1", "metric2", "metric3"),
Type2 = c("metric4","metric5")
),
options = list('plugins' = list('remove_button'))
)
),
column(2,
uiOutput(outputId = "lowerThresholdText"),
showLowHighSlidersUI("sliders-metric2")
)
)
)
server <- function(input, output){
ret <- callModule(module = showLowHighSliders,
id = "sliders-metric2",
metrics_selected=reactive(input$metricID))
output$lowerThresholdText <- renderText({
if(!is.null(input$metricID )){
if(input$metricID == 'metric2'){
paste("Lower Value: ", ret() )
}
}
})
}
shinyApp(ui, server)
Shiny module: showLowHighSliders.R
showLowHighSlidersUI <- function(id) {
ns <- NS(id)
fluidPage(
fluidRow(
column(12,
tagList(
# uiOutput(ns("lowerThresholdText")),
uiOutput(ns("lowerThresholdSlider"))
)
)
)
)
}
# Function for module server logic
showLowHighSliders <- function(input, output, session, metrics_selected) {
reactive({input$mySlider})
output$lowerThresholdSlider <- renderUI({
#print(metrics_selected())
if(!is.null(metrics_selected() ) ){
if('metric2' %in% metrics_selected() ){
sliderInput(
inputId = "mySlider",
label = "",
min = 0,
max = 200,
value = 20
)
}
}
})
# output$lowerThresholdText <- renderText({
# #print(metrics_selected)
# if(!is.null(metrics_selected() )){
# if('SMA' %in% metrics_selected()){
# paste("Lower SMA: ", input$mySlider )
# }
# }
#
# })
}
I was also unable to access the dynamic input slider value within the module itself shown in the commented part.
Any help is appreciated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…