Shiny validate似乎不适用于eventReactive:
shinyServer(function(input, output, session) {
observe({
switch <- input$switch
if (switch == "hide") {
# https://shiny.rstudio.com/gallery/update-input-demo.html
updateNumericInput(session, "n", "X", min = 0, max = 100, value = 0)
}
})
ntext <- eventReactive(input$goButton, {
validate(
need(input$switch != "hide", "Please select a data set")
)
input$n
})
output$text <- renderText({
ntext()
})
})
shinyUI(pageWithSidebar(
headerPanel("Click the button"),
sidebarPanel(
radioButtons(
inputId = "switch",
label = "Select hide or show:",
choices = c(
"Show" = "show",
"Hide" = "hide"
),
selected = NULL,
inline = FALSE
),
conditionalPanel(
condition = "input.switch == 'show'",
numericInput("n", "N:", min = 0, max = 100, value = 0)
),
actionButton("goButton", "Go!")
),
mainPanel(
textOutput("text")
)
))
任何想法如何将它与eventReactive一起使用?