Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

r - Facing issues to access shiny module dynamic input value

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.

enter image description here

Any help is appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...