一个小应用程序来过滤公司的销售
library(dplyr)
library(tidyr)
library(DT)
company=c("A","L","S","T","W","A","L","S","T","W")
sales=c(120,140,160,180,200,120,140,160,180,200)
server <- function(input, output) {
output$theCustomersList <- renderUI({
list(
selectInput("customer", "Choose a customer:",
c("A","L","S","T","W")
,selectize=FALSE
,multiple=TRUE
,selected="A"
)
)})
output$result <- DT::renderDataTable(data_frame(company,sales) %>% filter(company%in%input$customer))
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
uiOutput("theCustomersList")
),
mainPanel(DT::dataTableOutput('result'))
)
)
shinyApp(ui = ui, server = server)
这样可以正常工作,但如果我将其更改为使用postgresql表作为使用src_postgresql的销售数据的来源,如果我只从下拉列表中选择一家公司,我会收到错误。
基本上,生成的SQL提供了以下内容
Error: RS-DBI driver: (could not Retrieve the result : ERROR: syntax error at or near "'A'" LINE 4: ... AND "company" IN 'A'
有想法的人吗?
更新....这绝对是一个数据库问题。当过滤器应用于内存数据帧时,“%in%”构造可以使用单个选择或多个选择。当应用于postgres源时,括号将遗漏在生成的sql中,这意味着SQL格式不正确。
RS-DBI driver: (could not Retrieve the result : ERROR: syntax error at or near "'A'"
LINE 3: WHERE "company" IN 'A'