I've read on topics that it's not possible to reset value of an actionButton with Shiny Package, but I couldn't find any trick to solve my problem.
I'd like to delete the text and the button in the main panel with this code :
library(shiny)
shinyUI(fluidPage(
titlePanel("Trying to reset text !"),
sidebarLayout(
sidebarPanel(
actionButton("button1","Print text")
),
mainPanel(
textOutput("textToPrint"),
br(),
uiOutput("uiButton2")
)
)
))
shinyServer(function(input, output) {
output$textToPrint <- renderText({
if(input$button1==0) (return(""))
else (return("Button clicked"))
})
output$uiButton2 <- renderUI({
if(input$button1==0) (return ())
else (return(actionButton("button2","Reset text and this button")))
})
})
What is the alternative to impossible input$button1 = 0 ?
Thanks in advance for your help,
Matt
Thanks to Joe Cheng, here is a nice way of doing it :
shinyServer(function(input, output) {
values <- reactiveValues(shouldShow = FALSE)
observe({
if (input$button1 == 0) return()
values$shouldShow = TRUE
})
observe({
if (is.null(input$button2) || input$button2 == 0)
return()
values$shouldShow = FALSE
})
output$textToPrint <- renderText({
if (values$shouldShow)
"Button clicked"
})
output$uiButton2 <- renderUI({
if (values$shouldShow)
actionButton("button2","Reset text and this button")
})
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With