1

I am trying to create a dynamic query using select input.

Something like

Select * from basket where fruits in("apple","banana","cherry")

I have a table called fruit_list which populates my selectinput box.

selectInput("fruit_list", label = h5("Select fruit"), multiple = T, 
  choices = (dbGetQuery(conn, "SELECT fruit from fruit_list');"))) 

So far, when i renderprint my selection I get "apple" "banana" "cherry" I need a comma between the elements to get "apple","banana","cherry" When i choose a single element from the multiselect box "apple"

Select * from basket where fruits in("apple")

my application runs perfectly. However, when i select more than one element "apple" "banana" I get an error: Expecting a single string value: [type=character; extent=2].

MrFlick
  • 195,160
  • 17
  • 277
  • 295
chchi
  • 21
  • 2
  • Possible duplicate of [Creating a SQL query using selectinput in R shiny](https://stackoverflow.com/questions/58066371/creating-a-sql-query-using-selectinput-in-r-shiny) – yusuzech Sep 24 '19 at 19:07
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Show more exactly what code is being run. – MrFlick Sep 24 '19 at 19:07

1 Answers1

0

paste('dbGetQuery(conn,"Select fruit from fruits;", collapse =', '))

thmschk
  • 614
  • 3
  • 16
  • This opens the app up to many security vulnerabilities such as SQL injection. Please do not do this. Better options suggested by @yifyan in the comments above. – Sada93 Sep 24 '19 at 21:53
  • uh, didn't know that. Quite interesting, could you give me some details on the security vulnerabilities. – thmschk Sep 24 '19 at 22:01