我正在尝试创建一个闪亮的flexdashboard,它显示SQL查询的结果。我的代码包含提供给查询的网站,月份和年份的可选参数。我不能为我的生活弄清楚如何渲染查询结果,任何帮助将不胜感激。这是代码:
Hi
Change apple pear guava mango banana pear0
It's hot outside
Change tom greg pear harry steve pear1
George is a cool guy
Change mary lucy becky pear jill pear2
thank you
我尝试使用Hi
Change apple orange guava mango banana pear0
It's hot outside
Change tom greg fred harry steve pear1
George is a cool guy
Change mary lucy becky karly jill pear2
thank you
,# ---
# title: "Site Dashboard"
# output: flexdashboard::flex_dashboard
# runtime: shiny
# ---
{r setup, include=FALSE}
library(dplyr)
library(sqldf)
Column {.sidebar}
selectInput("site", label = "WIM Site",
choices = c("26","27"),
selected = "26")
numericInput("month", label = "Month",
value = 12, min = 1, max = 12, step = 1)
selectInput("year", label = "Year",
choices = c("2014","2015","2016"),
selected = "2015")
Column
-----------------------------------------------------------------------
### Query Results
db <- dbConnect(SQLite(), dbname="N:/TrafMon/WIM/Ian/minWIM.sqlite")
query<-reactive({
paste("SELECT * FROM", paste("wim",input$site,"_", input$year,
sep=""),paste("WHERE month =="),input$month, "LIMIT 5")
})
a <- reactive({
sqldf(query, dbname="N:/TrafMon/WIM/Ian/minWIM.sqlite")
})
query
renderTable(a)
,renderTable(a())
渲染表格。什么都没有效果。我应该注意在Rstudio中运行相同的查询代码会产生预期的输出,因此问题不在于查询。
答案 0 :(得分:2)
对于使用reactive
,您需要在(在所有被动反应中)
()
喜欢:
sqldf(query(), dbname="N:/TrafMon/WIM/Ian/minWIM.sqlite")
renderTable(a())