title: R Shiny : reactive data selection trought multiple selectInput in a postgresql/postgis db query with regular expression
body: <p>I'm trying to set up a ShinyApp which can access to a PostGreSQL/PostGIS database and perform reactive queries according to user inputs via selectInput widget.</p>
  
  <p>I succeed to perform it with single inputs following this example (<a href="https://www.cybertec-postgresql.com/en/visualizing-data-in-postgresql-with-r-shiny/" rel="nofollow noreferrer">https://www.cybertec-postgresql.com/en/visualizing-data-in-postgresql-with-r-shiny/</a>). My working code (sorry for non reprex example, but I cannont provide my database login for security purpose).</p>
  
  <pre><code>pool &lt;- dbPool(drv = dbDriver("PostgreSQL", max.con = 100), user = "user", password = "pswd", host = "000.000.00.000", port = 5432, dbname = "db_name", idleTimeout = 3600000)
  
  typology &lt;- dbGetQuery(pool, "SELECT type FROM table GROUP BY type")
  all_typo &lt;- sort(unique(typology$type))
  
  area_agripag &lt;- dbGetQuery(pool, "SELECT area_name FROM table GROUP BY area_name")
  all_area &lt;- sort(unique(area_agripag$area_name))
  
  ui &lt;- fluidPage(
      sidebarLayout(
          sidebarPanel(
              selectInput(
                  inputId = "area",
                  label = "Select a district",
                  choices = all_area,
                  selected = 'district_1',
                  multiple = FALSE,
                  selectize = FALSE
              ),
              selectInput(
                  inputId = "typo",
                  label = "Select a type",
                  choices = all_typo,
                  selected = 'type1',
                  multiple = FALSE,
                  selectize = FALSE
              )
          ),
          mainPanel(
              tabsetPanel(
                  tabPanel("graph", plotOutput("plot")),
                  tabPanel("Table", dataTableOutput("table"))
              )
          )
      )
  )
  
  server &lt;- function(input, output, session) {
  
      selectedData &lt;- reactive({
          req(input$area)
          req(input$typo)
          query &lt;- sqlInterpolate(ANSI(),
                  "SELECT year, SUM(surface) 
                  FROM table 
                  WHERE area_name = ?area_name 
                  AND type = ?type 
                  GROUP BY year;",
              area_name = input$area, type = input$typo)
          outp &lt;- as.data.frame(dbGetQuery(pool, query))
      })
  
      output$table &lt;- DT::renderDataTable({
          DT::datatable(  data = selectedData(),
                  options = list(pageLength = 14),
                  rownames = FALSE)
      })
  
      output$plot &lt;- renderPlot({
          ggplot( data = selectedData(), aes(x = year, y = sum)) + geom_point()
      })
  
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>What I want to do is editing the reactive query in the server part in order to allow multiple selectInput. I should add IN operator instead of = in the sql query :</p>
  
  <pre><code>selectedData &lt;- reactive({
          req(input$area)
          req(input$typo)
          query &lt;- sqlInterpolate(ANSI(),
                  "SELECT year, SUM(surface) 
                  FROM table 
                  WHERE area_name IN (?area_names) 
                  AND type IN (?types) 
                  GROUP BY year;",
              area_names = input$area, types = input$typo)
          outp &lt;- as.data.frame(dbGetQuery(pool, query))
      })
  </code></pre>
  
  <p>Next I know I should format the area_names / types vector returned by a multiple selectInput with some automatic regular expression. I want to wrap each elements of the vector with '', in order to accord with the SQL syntax. 
  For example, I want to transfrom the following multiple input$area vector :</p>
  
  <pre><code>area1 area2 area3
  </code></pre>
  
  <p>to</p>
  
  <pre><code>'area1', 'area2', 'area3'
  </code></pre>
  
  <p>In order to store it in the area_names sqlInterpolate argument.</p>
  
  <p>Anyone has an idea how to perform this? Thanks to all contributions.</p>