I am trying to use a validate
statement within an observeEvent
section of my shiny app but when the condition isn't met no error message is returned. It just remains a blank screen. Here is a reproducible example:
require(shiny)
runApp(
list(
ui = pageWithSidebar(
headerPanel("test"),
sidebarPanel(
p("Demo Page."),
sliderInput("sldr", "Select a value", min = 0, max = 10, value = 5),
actionButton("btn", "Push Me!")
),
mainPanel(
verbatimTextOutput("text")
)
),
server = function(input, output){
observeEvent(input$btn, {
validate(
need(input$sldr > 5, "Require > 5")
)
output$text <- renderText({
"hello world"
})
})
}
)
)
Right now, when I start up the app and push the Push Me!
action button nothing happens at all (the validate
is stopping the processing) but no error message is returned, just a white screen. If I change the selected value to 6
then it proceeds and prints the message.
Why is the validate
not getting displayed?
I guess because observeEvent
has no where to send the message to. Pushing the validate inside the print works the way you want it to and makes more sense to me.
But it might not be exactly what you need. Not sure if the entire observeEvent
command is terminated for example.
require(shiny)
runApp(
list(
ui = pageWithSidebar(
headerPanel("test"),
sidebarPanel(
p("Demo Page."),
sliderInput("sldr","Select a value",min = 0,max = 10,value = 5),
actionButton("btn","Push Me!")
),
mainPanel(
verbatimTextOutput("text")
)
),
server = function(input,output) {
observeEvent(input$btn,{
output$text <- renderText({
validate(
need(input$sldr > 5,"Require > 5")
)
"hello world"
})
})
}
)
)
Yielding:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.