Reputation: 843
I am attempting to create a shiny flexdashboard that displays the results of a SQL query. My code includes selectable parameters for a site, month and year that feed into the query. I cannot for the life of me figure out how to render the query results, any help would be greatly appreciated. Here's the code:
# ---
# 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)
I've tried rendering the table with renderTable(a())
, renderText(a())
, renderText(a)
. Nothing appears to work. I should note that running the same query code in Rstudio produces the expected output, so the problem is not with the query.
Upvotes: 0
Views: 1153
Reputation: 7871
For use reactive
you need added ()
after ( in all reactives)
like:
sqldf(query(), dbname="N:/TrafMon/WIM/Ian/minWIM.sqlite")
renderTable(a())
Upvotes: 2