please correct this code server <- function(input, output) { weather = reactive({ DB =…
- User
please correct this code server <- function(input, output) { weather = reactive({ DB = do.call(dbConnect, DB_PARAMETERS) dbGetQuery(DB, 'SELECT * FROM meteo WHERE
date<= ? AND ? <=date;' , params = c(inputperiod[2])) dbDisconnect(DB) })output$temp = renderTable({weather}) }
- Assistant
Your code has a few issues that should be fixed:
weatherreactive needs to explicitly return the result of the query, anddbDisconnectshould be called after the query, but before returning.renderTable({weather})is passing the reactive expression itself, but you need to call it:weather().- The SQL query's parameter ordering seems inverted or at least may cause logical issues.
- Better to use
on.exit(dbDisconnect(DB))to ensure the database disconnects even if an error occurs. - Backticks around
dateare fine but ensure consistency in the query.
Here is the corrected code:
r - User
ok, now I have an issue, I don't know how to use Rshimy dateRangeInput
- Assistant
No problem! The
dateRangeInputfunction in Shiny is a UI component that lets users select a range of dates (a start and an end). You can then access that range in your server code via , which returns a vector of two Dates.