【发布时间】:2022-01-23 16:40:32
【问题描述】:
我想获取从 selectInput() 中选择的项目。但是,似乎只有第一项可以转移到 server()。 用户界面:
sidebarLayout(
sidebarPanel(width = 4,
selectInput("cell_marker_density_surv", "Cell type", choices = cell_list,
selected = colnames(density)[1:3], multiple = TRUE),
textOutput("warning_density_roc_1"),
),
mainPanel(width = 8,
)
)
服务器()
warning_density_roc_1_output <- reactive({
a = input$cell_marker_density_surv
paste0(input$cell_marker_density_surv, collapse = ",")
})
output$warning_density_roc_1 <- renderText(warning_density_roc_1_output())
如我们所见,即使在默认情况下,也只显示第一项。
我意识到与这些问题相关的问题很多,但我不知道如何解决。它是由 selectInput() 函数本身引起的吗?实际上,我想在选择的输入超过五个时给出警告,所以我需要知道选择了多少项。你可以帮帮我吗?谢谢!
以下是根据第一个答案修改的代码:
library(shiny)
mpg <- ggplot2::mpg
library(shinyFeedback)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
width = 4,
textOutput("warning_density_roc_1"),
selectInput("cell_marker_density_surv", "Cell type",
choices = names(mpg),
selected = names(mpg)[1:6], multiple = TRUE
)
),
mainPanel(width = 8, )
)
)
server <- function(input, output, session) {
warning_density_roc_1_output <- reactive({
print(length(input$cell_marker_density_surv))
num_input_density_roc <- if(length(input$cell_marker_density_surv) > 5) {
print("TRUE")
TRUE
} else {
print("FALSE")
FALSE
}
num_input_density_roc
feedbackWarning("cell_marker_density_surv", num_input_density_roc, "Warning, more than five items selected.")
})
output$warning_density_roc_1 <- renderText(warning_density_roc_1_output())
}
shinyApp(ui, server)
但是,feedbackWarning() 无法正常工作。
【问题讨论】:
标签: r shiny shiny-server shinyjs selectinput