输入以“iris$Petal.Width - iris$Species”格式显示。在选定的输入上,要拆分的数据和 iris$Petal.Width 单独用于过滤整个数据。示例:所选值与图像中的一样。
尝试获取像 dplyr::filter(iris,iris$Petal.Width %in% c('0.2','0.3','0.1','0.6','1.4')) 这样的数据如何形成 c(' 0.2','0.3','0.1','0.6','1.4') 动态。
为了便于理解,以这个例子为例,实际上输入是 A001 - Description1,A002 - Description2 格式。需要取A001、A002组成c('A001','A002')。
尝试使用以下代码:
## run in interactive R sessions
if (interactive()) {
ui <- fluidPage(
selectizeInput('ipdesc', label='Selector',
choices = as.list(c(unique(paste(iris$Petal.Width,iris$Species,sep = " - ")))),
multiple = TRUE,
options = list(maxItems = 5)
),
p("Select Codes (Max 5), then press 'Go'"),
actionButton("go", label = "Go"),
tableOutput("selected")
)
server <- function(input, output) {
#
output$selected <- renderTable({
filterdata()
})
filterdata <- eventReactive(input$go,{
x=c()
cnt = length(input$ipdesc)
for (i in 1:cnt){
if (i != cnt) {
x[i] = cat(sapply(strsplit(input$ipdesc[i], " - "), "[", 1),",")
}
else
{x[i] = cat(x[1],sapply(strsplit(input$ipdesc[i], " - "), "[", 1))}
} })
#
}
shinyApp(ui, server)
}