我的数据如下:
A B C
x 1 NA
x 2 NA
x 2 NA
y 1 NA
y 2 NA
z 2 NA
z 3 NA
z 3 NA
z 2 NA
我需要在我的pickerInput函数中将A的每个值分组
library(shiny)
library(shinyWidgets)
x <- read.csv("Example.csv", sep=";")
ui <- fluidPage(
pickerInput("x", "Pick :", choices = x$A, multiple = T)
)
server <- function(input, output) {}
shinyApp(ui, server)
我希望在选择框中显示的内容是:
x
y
z
相反,我得到x y z的每次出现
那么如何将这些值分组?
我设法使用了闪亮包中的传统selectInput函数来实现这一点,但是对于我的目的而言,shinyWidget函数中的“全选/取消全选”确实很有趣
答案 0 :(得分:0)
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
fileInput("file1", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv"),
),
uiOutput("selection")
)
server <- function(input, output) {
output$selection <- renderUI({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath)
tagList(
selectizeInput("dynamicselctor", "Pick: ", choices = unique(df[[1]]), multiple = TRUE),
pickerInput("dynamicselctor2", "Pick: ", choices = unique(df[[1]]), multiple = TRUE)
)
})
}
shinyApp(ui, server)
从服务器端呈现PickerInput
或selectizeInput
也是一种选择(但通常应该可以)