-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Basically, the current behavior is the opposite of what the argument name and function documentation says. Shouldn't it be switched?
Current behavior:
we have an output, let's say a table. The data is invalidated and the condition being tested by req(condition, cancelOutput = TRUE) is not truthy.
If the output should be canceled (cancelOutput = TRUE), wouldn't it make sense for there to be NO output, since it's been cancelled?
What happens instead, is that the table remains the same.
If we want the table to not be displayed if the condition is not truthy, we need to set req(condition, cancelOutput = FALSE). This is also the default value of the cancelOutput argument.
Here's a quick illustration:
library(shiny)
ui <- fluidPage(
actionButton("reset", "Reset table"),
tableOutput("mytable")
)
server <- function(input, output, session) {
mydata <- reactive(
# the numbers will increase as the button is pressed
data.frame(x = 1:10 * input$reset,
y = 2:11 * input$reset)
)
output$mytable <- renderTable({
req(input$reset < 3,
cancelOutput = T)
mydata()
})
}
shinyApp(ui, server)
Proposal
Rather than switching what TRUE and FALSE do here, perhaps the better solution would be to give the argument a better name. Perhaps persistCurrentOutput=TRUE
?