How to pass input variable to SQL statement in R shiny?

后端 未结 2 1964
耶瑟儿~
耶瑟儿~ 2020-12-09 14:00

Usually, variables can be passed to SQL statements using paste. Interestingly this doesn\'t work with input variables in R shiny. Using the below code I get the following er

2条回答
  •  臣服心动
    2020-12-09 14:12

    For flexibility you can also use sub function to substitute part of the query string, this is quite clean approach

    table <- reactive({ 
      my_query <- 'SELECT a,b FROM table1 WHERE id = SOMETHING AND created_at >= 2015-08-01'
      my_query <- sub("SOMETHING",input$segment,my_query)
      dbGetQuery(database,noquote(my_query))
    })
    

提交回复
热议问题