多个 =T 时选择输入不更新
Selectinput not updated when multiple =T
我开发了一个闪亮的小应用程序,但我希望它在我 select 和 multiple =T
一起显示两个数据集的变量时显示它们。有什么想法吗?
ui.r
library(shiny)
bootstrapPage(
selectInput('dataset', 'Choose data set', c('mtcars', 'iris'),multiple = T),
selectInput('columns', 'Choose variable', "")
)
server.r
function(input, output, session){
# updates variable names based on selected dataset
outVar = reactive({
names(get(input$dataset))
})
# create separate observeEvents to
observeEvent(input$dataset, {
updateSelectInput(session, "columns", choices = outVar())
})
}
您需要将选定的输入作为列表传递给 lapply
函数并迭代读取 input$dataset
中的数据集以获得 names()
您可以尝试以下方法:
# updates variable names based on selected dataset
outVar = reactive({
unlist(lapply(as.list(input$dataset), function(x){data <- get(x);names(data)}))
})
完整的工作示例:
library(shiny)
ui <- bootstrapPage(
selectInput('dataset', 'Choose data set', c('mtcars', 'iris'),multiple = T),
selectInput('columns', 'Choose variable', "")
)
server <- function(input, output, session){
# updates variable names based on selected dataset
outVar = reactive({
unlist(lapply(as.list(input$dataset), function(x){data <- get(x);names(data)}))
})
# create separate observeEvents to
observeEvent(input$dataset, {
updateSelectInput(session, "columns", choices = outVar())
})
}
shinyApp(ui, server)
我开发了一个闪亮的小应用程序,但我希望它在我 select 和 multiple =T
一起显示两个数据集的变量时显示它们。有什么想法吗?
ui.r
library(shiny)
bootstrapPage(
selectInput('dataset', 'Choose data set', c('mtcars', 'iris'),multiple = T),
selectInput('columns', 'Choose variable', "")
)
server.r
function(input, output, session){
# updates variable names based on selected dataset
outVar = reactive({
names(get(input$dataset))
})
# create separate observeEvents to
observeEvent(input$dataset, {
updateSelectInput(session, "columns", choices = outVar())
})
}
您需要将选定的输入作为列表传递给 lapply
函数并迭代读取 input$dataset
中的数据集以获得 names()
您可以尝试以下方法:
# updates variable names based on selected dataset
outVar = reactive({
unlist(lapply(as.list(input$dataset), function(x){data <- get(x);names(data)}))
})
完整的工作示例:
library(shiny)
ui <- bootstrapPage(
selectInput('dataset', 'Choose data set', c('mtcars', 'iris'),multiple = T),
selectInput('columns', 'Choose variable', "")
)
server <- function(input, output, session){
# updates variable names based on selected dataset
outVar = reactive({
unlist(lapply(as.list(input$dataset), function(x){data <- get(x);names(data)}))
})
# create separate observeEvents to
observeEvent(input$dataset, {
updateSelectInput(session, "columns", choices = outVar())
})
}
shinyApp(ui, server)