if (interactive()){
ui <- fluidPage(
h4("Use buttons to show and hide loaders with different methods"),
spsDepend("addLoader"), # optional
tags$b("Replace"), br(),
actionButton("b_re_start", "Replace"),
actionButton("b_re_stop", "stop replace"),
br(), tags$b("Inline"), br(),
actionButton("b_in_start", "Inline"),
actionButton("b_in_stop", "stop inline"),
br(), tags$b("Full screen"), br(),
actionButton("b_fs_start", "Full screen 2s"), br(),
h4("Add loaders to a big HTML chunk"),
actionButton("chunk_start", "Chunk loader"),
actionButton("chunk_stop", "Stop"), br(),
column(6,
id = "chunk",
style = "background-color: #eee",
h5("Here is some text 12345"),
tags$hr(),
icon("house"),
p("blablablablablablablablablablablablablablablablablablablabla"),
p("blablablablablablablablablablablablablablablablablablablabla"),
p("blablablablablablablablablablablablablablablablablablablabla"),
p("blablablablablablablablablablablablablablablablablablablabla")
)
)
server <- function(input, output, session) {
# Init loaders
loader_replace <- addLoader$new("b_re_start", type = "facebook")
loader_inline <- addLoader$new("b_in_start", color = "green", method = "inline")
loader_fs <- addLoader$new(
"b_fs_start", color = "pink", method = "full_screen",
bg_color = "#eee", height = "30rem", type = "heart"
)
loader_chunk <- addLoader$new(
"chunk", type = "spinner", color = "orange",
footer = h5("chunk loader")
)
# toggle loaders
## replace
observeEvent(input$b_re_start, {
loader_replace$show()
})
observeEvent(input$b_re_stop, {
loader_replace$hide()
})
## inline
observeEvent(input$b_in_start, {
loader_inline$show()
})
observeEvent(input$b_in_stop, {
loader_inline$hide()
})
## full screen
observeEvent(input$b_fs_start, {
loader_fs$show()
Sys.sleep(2)
loader_fs$hide()
})
## chunk
observeEvent(input$chunk_start, {
loader_chunk$show()
})
observeEvent(input$chunk_stop, {
loader_chunk$hide()
})
}
shinyApp(ui, server)
}
if (interactive()){
ui <- bootstrapPage(
spsDepend("addLoader"), # optional
h4("Add loaders to Shiny `render` events"),
tags$b("Replace"), br(),
selectizeInput(inputId = "n_re",
label = "Change this to render the following plot",
choices = c(10, 20, 35, 50)),
plotOutput(outputId = "p_re"),
br(), tags$b("Full screen"), br(),
selectInput(inputId = "n_fs",
label = "Change this to render the following plot",
choices = c(10, 20, 35, 50)),
plotOutput(outputId = "p_fs")
)
server <- function(input, output, session) {
# create loaders
l_re <- addLoader$new("p_re")
l_fs <- addLoader$new(
"p_fs", color = "pink", method = "full_screen",
bg_color = "#eee", height = "30rem", type = "grid",
footer = h4("Replotting...")
)
# use loaders in rednering
output$p_re <- renderPlot({
on.exit(l_re$hide())
# to make it responsive
# (always create a new one by calculating the new height and width)
l_re$recreate()$show()
Sys.sleep(1)
hist(faithful$eruptions,
probability = TRUE,
breaks = as.numeric(input$n_re),
xlab = "Duration (minutes)",
main = "Geyser eruption duration")
})
output$p_fs <- renderPlot({
on.exit(l_fs$hide())
l_fs$show()
Sys.sleep(1)
hist(faithful$eruptions,
probability = TRUE,
breaks = as.numeric(input$n_fs),
xlab = "Duration (minutes)",
main = "Geyser eruption duration")
})
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab