# Note these examples use several other shinyjs functions as the onclick code
if (interactive()) {
shiny::shinyApp(
ui = shiny::fluidPage(
useShinyjs(), # Set up shinyjs
shiny::actionButton("btn", "Click me"),
shiny::p(id = "element", "Click me to change my text")
),
server = function(input, output, session) {
# Change the following lines for more examples
onclick("btn", info(date()))
onclick("element", text("element", "Hello!"))
}
)
}
# The shinyjs function call in the above app can be replaced by
# any of the following examples to produce similar Shiny apps
onclick("btn", toggle("element"))
onclick(expr = text("element", date()), id = "btn")
{onclick("btn", info(date())); onclick("btn", info("Another message"), TRUE)}
Run the code above in your browser using DataLab