我有一个闪亮的应用程序,其中包含各种输入,以及总结用户输入内容的 uiOutputs。我有一个按钮可以重置所有输入值并清除 uiOutputs,但是一旦清除了 uiOutputs,它们就不再根据输入进行更新。
这不会重置 uiOutput:
library(shiny)
ui <- fluidPage(
selectInput('select1', label = 'test', choices = c('a', 'b', 'c'), selected = character(0)),
uiOutput('output1'),
actionButton('reset', 'reset')
)
server <- function(input, output, session) {
output$output1 <- renderUI(
if(length(input$select1) > 0) { ## this essentially determines whether the input is valid
h6(input$select1)
} else {
h6('')
}
)
observeEvent(input$reset, {
updateSelectInput(session, 'select1', selected = character(0))
print('clicked')
})
}
shinyApp(ui = ui, server = server)
这个重置它但不允许它根据输入再次更新:
library(shiny)
ui <- fluidPage(
selectInput('select1', label = 'test', choices = c('a', 'b', 'c'), selected = character(0)),
uiOutput('output1'),
actionButton('reset', 'reset')
)
server <- function(input, output, session) {
output$output1 <- renderUI(h6(input$select1))
observeEvent(input$reset, {
output$output1 <- renderUI(
h6('')
)
updateSelectInput(session, 'select1', selected = character(0))
print('clicked')
})
}
shinyApp(ui = ui, server = server)
如何使用renderUI()
语句重置 uiOutput,然后在选择新输入时再次更新?
谢谢!