# NOT RUN {
if (interactive()) {
library(shiny)
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
actionButton("btn", "Click me"),
textInput("text", "Text")
),
server = function(input, output) {
observeEvent(input$btn, {
# Change the following line for more examples
toggle("text")
})
}
)
}
# }
# NOT RUN {
# The shinyjs function call in the above app can be replaced by
# any of the following examples to produce similar Shiny apps
toggle(id = "text")
delay(1000, toggle(id = "text")) # toggle in 1 second
toggle("text", TRUE)
toggle("text", TRUE, "fade", 2)
toggle(id = "text", time = 1, anim = TRUE, animType = "slide")
show("text")
show(id = "text", anim = TRUE)
hide("text")
hide(id = "text", anim = TRUE)
# }
# NOT RUN {
## toggle can be given an optional `condition` argument, which
## determines if to show or hide the element
if (interactive()) {
shinyApp(
ui = fluidPage(
useShinyjs(),
checkboxInput("checkbox", "Show the text", TRUE),
p(id = "element", "Watch what happens to me")
),
server = function(input, output) {
observe({
toggle(id = "element", condition = input$checkbox)
})
}
)
}
# }
Run the code above in your browser using DataLab