【发布时间】:2018-12-02 16:20:57
【问题描述】:
selectizeInput 中的选项是否可以是数据框中的行?如果是这样,返回的数据是否会是所选行中的项目列表?我一直无法完成这项工作。在下面的代码中,cityInput 有效,因为选项是一个字符向量;但是locationInput不起作用,选择框中的项目列表是空的。
这是一种常见的情况,用户输入需要根据多列中的值进行选择以确定唯一的行。在下面的示例中,不同的城市具有相同的名称,并且使用州来唯一地确定位置。将两列粘贴在一起是一种解决方案,但在复杂的情况下,这种方法会变得混乱。
library(shiny)
locations <- data.frame(City=c("Ames", "Beaumont", "Beaumont", "Portland", "Portland"),
State=c("IA", "CA", "TX", "ME", "OR"))
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectizeInput("cityInput", "City", choices=NULL, selected=NULL),
selectizeInput("locationInput", "Location", choices=NULL, selected=NULL)
),
mainPanel("Main Panel")
)
)
server <- function(input, output, session) {
updateSelectizeInput(session, 'cityInput',
choices = locations$City,
server = TRUE
)
updateSelectizeInput(session, 'locationInput',
choices = locations,
server = TRUE
)
}
shinyApp(ui, server)
【问题讨论】:
标签: r shiny selectize.js