R-Shiny using Reactive renderUI value

前端 未结 1 771
感动是毒
感动是毒 2020-12-15 11:32

How do you use values obtained from a renderUI element in a reactive wrapper?

i.e. My code:

CompanyNames <- sqlQuery(connection, \"SELECT Companyn         


        
相关标签:
1条回答
  • 2020-12-15 12:10

    You would refer to the elements by their id for example input$compName. As a contrived example here is a simple shiny app with two selectInput's. The second selectInput choices depend on the value of the first. Referencing the output of widgets created by renderUI is no different from referencing the same widgets if they had been in UI.R from the beginning:

    library(shiny)
    myDF <- data.frame(A = 1:4, B = 3:6, C = 6:9, D = 10:13)
    runApp(
      list(
        ui = fluidPage(
          uiOutput("myList"),
          uiOutput("myNumbers")
          )
        , server = function(input, output, session){
          output$myList <- renderUI({
            selectInput("compName", "Company Name:", LETTERS[1:4])
          })
    
          output$myNumbers <- renderUI({
            selectInput("compNo", "Product Line:", myDF[, input$compName])
          })
        }
        )
      )
    
    0 讨论(0)
提交回复
热议问题