在清除用户在pickerInput的shinyWidget包下选择的选项时,我遇到了问题。下面的代码如下:
library(shinyWidgets)
library(shiny)
shinyApp(
ui = basicPage(
actionButton("show", "Click me!")
),
server = function(input, output){
observeEvent(input$show, {
showModal(
modalDialog(
h2("Select Years", align = "center"),
pickerInput(inputId = "Yearz", label = NULL,
choices = c(2012:2017), options = list(
`selected-text-format` = "count > 3", `actions-box` = TRUE),
multiple = TRUE, width = "100%")
)
)
})
observeEvent(input$Yearz, {
print(input$Yearz)
}
)
}
)我注意到,当选择的最后一个选项被取消选择时,无论是通过“取消选择所有”按钮还是通过手动方式,最后一个选项仍然保留在输入$Yearz下面。是否有一种方法可以使输入$_‘中的值全部为空?
发布于 2018-10-26 20:48:56
在pickerInput中没有选择时,服务器中的值为NULL,observeEvent忽略NULL,因此:
observeEvent(input$Yearz, {
print(input$Yearz)
}, ignoreNULL = FALSE)https://stackoverflow.com/questions/53016091
复制相似问题