如何让renderUI对用户从下拉列表中选择不同的值做出反应,而无需单击我的submitButton?闪亮:让renderUI对下拉列表做出反应not submitButton
我有一个包含3件事情wellPanel:
1)我的下拉列表
2)一套动态输入(通过我的renderUI函数创建,取决于选择的#1)
3 )submitButton
期望的行为:对下拉选择的更改为用户提供了不同的输入小部件。当他们准备好所选输入的结果时,他们点击submitButton,并在mainPanel中获得结果。
问题:我的renderUI只对单击submitButton后的下拉选择作出反应。据我所知,我需要隔离一些东西或使用observeEvent,但我一直无法弄清楚。
简单的例子:
rm(list = ls())
library(shiny)
ui <- fluidPage(
fluidRow(
column(4,wellPanel(
selectInput("analysis", label = "Type of Analysis:",
c("Award Total" = "total",
"Award Average" = "average"),
width = validateCssUnit("70%")),
uiOutput("filter_box"),
submitButton()
)),
column(8, textOutput("sample_text"))
)
)
server <- function(input, output, session){
output$filter_box <- renderUI({
if(input$analysis == "total"){
tagList(radioButtons(inputId = "input1", label = "Select One:",c("A", "B", "C"), selected = "A"))
} else {
tagList(checkboxGroupInput(inputId = "input2", label = "Select all that apply:",c("1","2","3","4","5")),
dateRangeInput(inputId = "input3", label = "Enter Date Range"))
}
})
output$sample_text <- renderText({
if(input$analysis == "total"){
input$input1
} else if(input$analysis == "average") {
c(input$input2, input$input3)
}
})
}
runApp(list(ui = ui, server = server))
您不需要使用submitButton,而是使用actionButton。 submitButtons是可怕的(闪亮的作者自己推荐它),因为它们导致了奇怪的反应行为。对不起,我不会给你一个解决方案,我只是建议你使用actionButton,而这个问题不会发生,那么 –