# use non-exported function from teal.slice
toggle_icon <- getFromNamespace("toggle_icon", "teal.slice")
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
actionButton("hide_content", label = "hide", icon = icon("xmark")),
actionButton("show_content", label = "show", icon = icon("check")),
actionButton("toggle_content", label = "toggle", icon = icon("angle-down")),
tags$br(),
tags$div(
id = "content",
verbatimTextOutput("printout")
)
)
server <- function(input, output, session) {
observeEvent(input$hide_content,
{
hide("content")
toggle_icon("toggle_content", c("fa-angle-down", "fa-angle-right"), one_way = TRUE)
},
ignoreInit = TRUE
)
observeEvent(input$show_content,
{
show("content")
toggle_icon("toggle_content", c("fa-angle-right", "fa-angle-down"), one_way = TRUE)
},
ignoreInit = TRUE
)
observeEvent(input$toggle_content,
{
toggle("content")
toggle_icon("toggle_content", c("fa-angle-right", "fa-angle-down"))
},
ignoreInit = TRUE
)
output$printout <- renderPrint({
head(faithful, 10)
})
}
if (interactive()) {
shinyApp(ui, server)
}
Run the code above in your browser using DataLab