显示查询结果的闪亮 flexdashboard
Shiny flexdashboard that displays the results of a query
我正在尝试创建一个闪亮的 flexdashboard 来显示 SQL 查询的结果。我的代码包括一个网站的 selectable 参数,输入查询的月份和年份。我终生无法弄清楚如何呈现查询结果,我们将不胜感激任何帮助。这是代码:
# ---
# 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)
渲染 table。似乎没有任何效果。我应该注意到 运行 Rstudio 中的相同查询代码会产生预期的输出,因此问题不在于查询。
要使用 reactive
,您需要在(在所有反应中)
之后添加 ()
赞:
sqldf(query(), dbname="N:/TrafMon/WIM/Ian/minWIM.sqlite")
renderTable(a())
我正在尝试创建一个闪亮的 flexdashboard 来显示 SQL 查询的结果。我的代码包括一个网站的 selectable 参数,输入查询的月份和年份。我终生无法弄清楚如何呈现查询结果,我们将不胜感激任何帮助。这是代码:
# ---
# 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)
渲染 table。似乎没有任何效果。我应该注意到 运行 Rstudio 中的相同查询代码会产生预期的输出,因此问题不在于查询。
要使用 reactive
,您需要在(在所有反应中)
()
赞:
sqldf(query(), dbname="N:/TrafMon/WIM/Ian/minWIM.sqlite")
renderTable(a())