I query data from R shiny app
output$ceb_selector <- renderUI({
selectInput("select_tab", label = ("ceb"),
choices = list("xx" , "yy", "All"),
selected = "All")
This is my old sql
t1 <- dbGetQuery(pool,statement = paste0("select ",input$date," , name ,
sum(",input$x1,"*y) as ",input$x1," ,
sum(gg) as ggsum
from table_name
where name = '",input$name,"'
and ",input$date," between '",input$date_range[1],"' and '",input$date_range[2],"'
group by ",input$date," ,name ") )
write.table(t1, file="emp.csv", sep = ",", row.names=FALSE)
I want to add where condition from input$ceb that have 3 choices = xx, yy, all
But in database column ceb only have data xx and yy don't have all (I want use 'all' to select both xx and yy)
What I thought is If input = xx will where ceb = xx
If input = yy will where ceb = yy
If input = All will where xx and yy
I tried
paste0("select ",input$date," , name ,
sum(",input$x1,"*y) as ",input$x1," ,
sum(gg) as ggsum
from table_name
where name = '",input$name,"'
and ",input$date," between '",input$date_range[1],"' and '",input$date_range[2],"'
and ceb =
case
when ",input$ceb," = xx then 'xx'
when ",input$ceb," = yy then 'yy'
end
group by ",input$date," ,name ")
AND
case
when ",input$ceb," = xx then and tab = 'xx'
when ",input$ceb," = yy then and tab = 'yy'
end
It's still error.
DBI::dbQuoteString(con, ...)for values, and perhapsDBI::dbQuoteIdentifierfor field/column names. (Otherwise, think sql-injection or just really-hard-to-troubleshoot problems.)'xx'and'yy'cases, should there be something different going on there?and ceb in ('xx','yy'); and if the input is "All", then you don't concatenate that string. I don't know, really, I don't know enough about the inputs or the table.input$...from shiny, this really has nothing to do with shiny in its core, is that right? BTW: an image of a data table (especially a single-column one that does not clarify things) is discouraged: it cannot be searched and breaks screen-readers. Consider adding "real data" in various forms, either fromdput(...),data.frame(...), or (least-preferred) copy output from the console; this last one is problematic in that there are lots of possible ambiguities that we cannot see well on the console.