I have a reactive drop down box in Rshiny with the values for years- 2016 to 2019. After the user chooses the year, the year has to be passed onto an sql query with the year as the parameter.
So I tried the line given below (where unique_vales2
holds the year values)
---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
social: [ "twitter", "facebook", "menu"]
runtime: shiny
```{r}
mydb = dbConnect(MySQL(), user='xxx', password='xxx',dbname='xxx',
host='xxx')
selectInput("year", "Choose year", choices = unique_values2)
num <- reactive(as.integer(input$year))
rs=dbSendQuery(mydb,paste("select * from employees where Year=",num," group
by job;"))
result=fetch(rs,n=-1)
```
But when I tried to use the num value in an sql query like given above,
It shows:
Error: cannot coerce the type 'closure' to vector of type 'character'.
Any way around this? Thanks in advance.