Hello,
I am trying to build an application through R shiny which takes input from users and runs a SQL query behind and gives the output. The input I am taking is not a single value as in I should be able to take multiple IDs, pass then through "IN" in SQL query and get the output. Below is how it looks:
ui<- fluidPage(
textInput(inputId = "id",label = "Input your IDs with single space between them"),
actionButton(inputId = "submit", label = "Run"),
)
server <- function(input,output) {
data <- eventReactive(input$submit, {
dbGetQuery(pool,
sqlInterpolate(ANSI(),
"select id, sum(XYZ)
from tableA
where id in (?id)
and date = '2018-04-30'
group by 1;",
id = gsub(" ","','",input$id) #replacing spaces with ',' which is in SQL format ex:'id1','id2'
)
)
})
output$table <- renderDataTable({
data()
})
}
I am taking different IDs separated with spaces and running a query to get the output. This is working fine if I paste one ID in the input text field but is not working when I input multiple IDs. Can somebody please help?