我正在尝试将 selectizeInput 的多个值传递给 MySQL 查询。
问题是在闪亮的应用程序中这种操作的正确语法是什么?
我尝试过并且正在使用一个值
library(shiny)
library(DBI)
library(RMySQL)
server <- shinyServer(function(input, output, session) {
con <- dbConnect(MySQL(), user='user', port = 3306,
password='pwd', dbname='db', host='host' )
on.exit(dbDisconnect(con), add = TRUE)
output$textview <- renderUI({
con <- dbConnect(MySQL(), user='user', port = 3306, password='pwd',
dbname='db', host='host' )
on.exit(dbDisconnect(con), add = TRUE)
text <- reactive({
dbGetQuery(con, statement =
paste0(" SELECT author, title, publicationDate, FROM publications
WHERE publications.year LIKE %'",input$year,"'% ")
)
})
text <-text()
HTML(text)
})
session$onSessionEnded(function() { dbDisconnect(con) })
})
ui_panel <-
tabPanel("Multi-Select Input Test",
sidebarLayout(
sidebarPanel(
selectizeInput('year', 'Select Year of publication:', choices =
publications.year, multiple = TRUE options = list(maxOptions = 5)
),
br(),
submitButton("Update Text View"),
br()
),
mainPanel(
tabsetPanel(tabPanel("Text",htmlOutput("textview"))
)
)
))
ui <- shinyUI(navbarPage(" ",ui_panel))
runApp(list(ui=ui,server=server))
MySQL 命令中允许我从 selectizeInput (input$year) 传递多个值的正确语法是什么?我尝试使用 IN 而不是 LIKE 如下,但它不起作用
text <- reactive({
dbGetQuery(con, statement =
paste0(" SELECT author, title, publicationDate, FROM
publications WHERE publications.year IN %'",input$year,"'% ")
)
})