【发布时间】:2016-03-29 23:08:10
【问题描述】:
我正在尝试创建一个闪亮的 flexdashboard 来显示 SQL 查询的结果。我的代码包括输入查询的站点、月份和年份的可选参数。我一生都无法弄清楚如何呈现查询结果,任何帮助将不胜感激。代码如下:
# ---
# 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())、renderText(a())、renderText(a) 渲染表格。似乎没有任何效果。我应该注意,在 Rstudio 中运行相同的查询代码会产生预期的输出,所以问题不在于查询。
【问题讨论】:
-
哇,成功了!您想将其添加为答案吗?
标签: r shiny shinydashboard