I have the following in server.R
shinyServer(function(input, output) {
# builds a reactive expression that only invalidates
# when the value of input$goButton becomes out of date
# (i.e., when the button is pressed)
ntext <- eventReactive(input$goButton, {
input$n
})
output$nText <- renderText({
ntext()
})
})
and the following in ui.R
shinyUI(pageWithSidebar(
headerPanel("actionButton test"),
sidebarPanel(
numericInput("n", "N:", min = 0, max = 100, value = 50),
br(),
actionButton("goButton", "Go!"),
p("Click the button to update the value displayed in the main panel.")
),
mainPanel(
verbatimTextOutput("nText")
)
))
My goal is to make the go action button disappear once it is clicked five times and give a pop up window warning if clicked less than five times.
You don't need to define a reactive
n
. It is already the value ofinput$btn
.As @daattali is saying,
shinyjs
make this really easy, you can do it like this:Here's how you would hide the button without using shinyjs:
And finally without using observeEvent: