【发布时间】:2017-02-18 16:30:08
【问题描述】:
我正在尝试在带有 Shiny 的动态 sql 查询中使用 selectInput,但反应状态似乎出错了:
在没有活跃的反应上下文的情况下不允许操作。 (你试图做一些只能在反应式表达式或观察者内部完成的事情。)
我实际上是在使用带有 sql 查询的 RODBC,但这是对可重现示例的尝试。
服务器:
data(citytemp, package = "highcharter")
function(input, output) {
getCityData <- function(selectedCity) {
return(citytemp[[selectedCity]])
# hardcoded :
# return(citytemp$tokyo)
# dynamic sql query
# sql <- paste0("select * from cities where name = ", selectedCity)
}
cityData <- getCityData(input$cityFilter)
#render highchart with cityData
}
用户界面:
library("shiny")
library("shinydashboard")
selectInput("cityFilter", label = "City", choices = list("Tokyo" = "tokyo", "London" = "london", "Berlin" = "berlin"))
box(width = 6, highchartOutput("highchart"))
【问题讨论】: