如何在反应式包装器中使用从renderUI元素获得的值?

即我的代码:

CompanyNames <- sqlQuery(connection, "SELECT Companynm FROM RiskMgm_Company")

output$CompNameSelector <- renderUI({
selectInput("compName","Company Name:",as.vector(CompanyNames[,1]))
})

 CompID <- reactive({
CompID <<- sqlQuery(paste("SELECT CompanyID FROM RiskMgm_Company WHERE Companynm = '",compName,"'"))
})

output$MotorSelector <- renderUI({
selectInput("MachSer","Machine:",sqlQuery(connection,paste("SELECT Motor_func FROM RiskMgm_Motor WHERE Company_ID='",CompID,"'")))
})


我的错误:

Successfilly opened connection to db
Error in paste("SELECT CompanyID FROM RiskMgm_Company WHERE Companynm = '",  :
could not find function "compName"


我究竟做错了什么?本质上,我想要的是SQL查询给出的公司列表。然后根据所选择的公司,将在下一个下拉框中显示该公司的电动机

谢谢

最佳答案

您可以通过其ID引用元素,例如input$compName。作为一个人为的例子
是一个带有两个selectInput的简单闪亮应用程序。第二个selectInput选择取决于第一个的值。引用renderUI创建的窗口小部件的输出与引用相同的窗口小部件(如果它们从一开始就在UI.R中)没有什么不同:

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])
      })
    }
    )
  )

08-07 03:37