Learn R Programming

waiter (version 0.1.0)

waiter: Waiter

Description

Programatically show and hide loading screens.

Usage

use_waiter(include_js = TRUE)

waiter_use(include_js = TRUE)

show_waiter( html = "", color = "#333e48", logo = "", id = NULL, hide_on_render = FALSE )

waiter_show( id = NULL, html = spin_1(), color = "#333e48", logo = "", hide_on_render = !is.null(id) )

show_waiter_on_load(html = "", color = "#333e48", logo = "")

waiter_show_on_load(html = spin_1(), color = "#333e48", logo = "")

hide_waiter_on_drawn(id)

waiter_hide_on_render(id)

hide_waiter(id = NULL)

waiter_hide(id = NULL)

update_waiter(html = "", id = NULL)

waiter_update(id = NULL, html = NULL)

Arguments

include_js

Whether to include the Javascript dependencies, only set to FALSE if you use show_waiter_on_load.

html

HTML content of waiter, generally a spinner, see spinners.

color

Background color of loading screen.

logo

Logo to display.

id

Id of element to hide or element on which to show waiter over.

hide_on_render

Set to TRUE to automatically hide the waiter when the plot in id is drawn. Note the latter will only work with shiny plots, tables, htmlwidgets, etc. but will not work with arbitrary elements.

Functions

  • use_waiter and waiter_use: waiter dependencies to include anywhere in your UI but ideally at the top.

  • waiter_show_on_load: Show a waiter on page load, before the session is even loaded, include in UI after use_waiter.

  • waiter_show: Show waiting screen.

  • waiter_hide: Hide any waiting screen.

  • waiter_update: Update the content html of the waiting screen.

  • waiter_hide_on_render: Hide any waiting screen when the output is drawn, useful for outputs that take a long time to draw, use in ui.

Examples

Run this code
# NOT RUN {
library(shiny)

ui <- fluidPage(
  use_waiter(), # dependencies
  waiter_show_on_load(spin_fading_circles()), #<U+00A0>shows before anything else 
  actionButton("show", "Show loading for 5 seconds")
)

server <- function(input, output, session){
  waiter_hide() #<U+00A0>will hide *on_load waiter
  
  observeEvent(input$show, {
    waiter_show(
      tagList(
        spin_fading_circles(),
        "Loading ..."
      )
    )
    Sys.sleep(3)
    waiter_hide()
  })
}

if(interactive()) shinyApp(ui, server)

# }

Run the code above in your browser using DataLab