• Stars
    star
    400
  • Rank 107,843 (Top 3 %)
  • Language
    CSS
  • License
    Other
  • Created over 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

βŒ› Add loading animations to a Shiny output while it's recalculating

shinycssloaders

βŒ› Add loading animations to a Shiny output while it's recalculating

R-CMD-check CRAN version


When a Shiny output (such as a plot, table, map, etc.) is recalculating, it remains visible but gets greyed out. Using {shinycssloaders}, you can add a loading animation ("spinner") to outputs instead of greying them out. By wrapping a Shiny output in withSpinner(), a spinner will automatically appear while the output is recalculating. You can also manually trigger a spinner using showSpinner().

In addition to showing spinners on outputs, you can also use showPageSpinner() to show a full-page spinner that covers the entire page.

You can choose from one of 8 built-in animation types, and customize the colour/size. You can also use your own image instead of the built-in animations. See the demo Shiny app online for examples.

Need Shiny help? I'm available for consulting.
If you find {shinycssloaders} useful, please consider supporting my work! ❀

This package is part of a larger ecosystem of packages with a shared vision: solving common Shiny issues and improving Shiny apps with minimal effort, minimal code changes, and clear documentation. Other packages for your Shiny apps:

Package Description Demo
shinyjs πŸ’‘ Easily improve the user experience of your Shiny apps in seconds πŸ”—
shinyalert πŸ—―οΈ Easily create pretty popup messages (modals) in Shiny πŸ”—
shinyscreenshot πŸ“· Capture screenshots of entire pages or parts of pages in Shiny apps πŸ”—
timevis πŸ“… Create interactive timeline visualizations in R πŸ”—
colourpicker 🎨 A colour picker tool for Shiny and for selecting colours in plots πŸ”—
shinybrowser 🌐 Find out information about a user's web browser in Shiny apps πŸ”—
shinydisconnect πŸ”Œ Show a nice message when a Shiny app disconnects or errors πŸ”—
shinytip πŸ’¬ Simple flexible tooltips for Shiny apps WIP
shinymixpanel πŸ” Track user interactions with Mixpanel in Shiny apps or R scripts WIP
shinyforms πŸ“ Easily create questionnaire-type forms with Shiny WIP

Table of contents

Example

For interactive examples and to see some of the features, check out the demo app.

Below is a simple example of what {shinycssloaders} looks like:

demo GIF

How to use

Simply wrap a Shiny output in a call to withSpinner(). If you have %>% loaded, you can use it, for example plotOutput("myplot") %>% withSpinner().

Basic usage:

library(shiny)

ui <- fluidPage(
    actionButton("go", "Go"),
    shinycssloaders::withSpinner(
        plotOutput("plot")
    )
)
server <- function(input, output) {
    output$plot <- renderPlot({
        input$go
        Sys.sleep(1.5)
        plot(runif(10))
    })
}
shinyApp(ui, server)

Using a full-page spinner:

library(shiny)

ui <- fluidPage(
    actionButton("go", "Go"),
    plotOutput("plot")
)
server <- function(input, output) {
    observeEvent(input$go, {
      showPageSpinner()
      Sys.sleep(1)
      hidePageSpinner()
    })
    output$plot <- renderPlot({
        plot(runif(10))
    })
}
shinyApp(ui, server)

You can also use {shinycssloaders} in Rmarkdown documents, as long as they use runtime: shiny.

Installation

For most users: To install the stable CRAN version:

install.packages("shinycssloaders")

For advanced users: To install the latest development version from GitHub:

install.packages("remotes")
remotes::install_github("daattali/shinycssloaders")

Features

8 customizable built-in spinners

You can use the type parameter to choose one of the 8 built-in animations, the color parameter to change the spinner's colour, and size to make the spinner smaller or larger (2 will make the spinner twice as large). For example, withSpinner(plotOutput("myplot"), type = 5, color = "#0dc5c1", size = 2).

Using a custom image

If you don't want to use any of the built-in spinners, you can also provide your own image (either a still image or a GIF) to use instead, using the image parameter.

Specifying the spinner height

The spinner attempts to automatically figure out the height of the output it replaces, and to vertically center itself. For some outputs (such as tables), the height is unknown, so the spinner will assume the output is 400px tall. If your output is expected to be significantly smaller or larger, you can use the proxy.height parameter to adjust this.

Manually triggering the spinner

Any Shiny output that uses withSpinner() will automatically show a spinner while it's recalculating. You can also manually show/hide an output's spinner using showSpinner()/hideSpinner().

Full-page spinner

You can also use showPageSpinner() to show a full-page spinner that will cover the entire page rather than a single Shiny output. Full page spinners support the same parameters as regular spinners, and can be removed with hidePageSpinner().

Add a message

Use the caption parameter to add a custom message under the spinner. The message can either be plain text ("Please wait") or HTML (div(strong("Loading"), br(), em("Please wait"))).

Setting spinner parameters globally

If you want all the spinners in your app to share some of the options, instead of specifying them in each call to withSpinner(), you can set them globally using R options. For example, if you want all spinners to be of a certain type and color, you can set options(spinner.type = 5, spinner.color = "#0dc5c1"). Similarly, for full-page spinners you can use page.spinner.type, page.spinner.color, etc to set default parameters instead of setting them in showPageSpinner().

Showing a spinner on top of the output

By default, the out-dated output gets hidden while the spinner is showing. You can change this behaviour to have the spinner appear on top of the old output using the hide.ui = FALSE parameter.

Sponsors πŸ†

There are no sponsors yet

{shinycssloaders} is the result of many days of work, including many more to come. Show your support and become the first sponsor for {shinycssloaders}!

Credits

The 8 built-in animations are taken from https://projects.lukehaas.me/css-loaders/.

The package was originally created by Andrew Sali.

More Repositories

1

beautiful-jekyll

✨ Build a beautiful and simple website in literally minutes. Demo at https://beautifuljekyll.com
HTML
5,297
star
2

advanced-shiny

🀹 Shiny tips & tricks for improving your apps and solving common problems
R
1,196
star
3

addinslist

πŸ“œ Discover and install useful RStudio addins
R
840
star
4

shinyjs

πŸ’‘ Easily improve the user experience of your Shiny apps in seconds
R
730
star
5

timevis

πŸ“… Create interactive timeline visualizations in R
R
654
star
6

ggExtra

πŸ“Š Add marginal histograms to ggplot2, and more ggplot2 enhancements
R
379
star
7

shiny-server

My personal Shiny server
R
252
star
8

shinyalert

πŸ—―οΈ Easily create pretty popup messages (modals) in Shiny
R
241
star
9

oldschool-github-extension

Revert GitHub's UI back to its classic look (before the June 23, 2020 update that has a flat, rounded and more whitespaced design).
CSS
227
star
10

colourpicker

🎨 A colour picker tool for Shiny and for selecting colours in plots (in R)
JavaScript
214
star
11

shinyforms

πŸ“ Easily create questionnaire-type forms with Shiny
R
162
star
12

shinyscreenshot

πŸ“· Capture screenshots of entire pages or parts of pages in Shiny apps
R
69
star
13

shinydisconnect

πŸ”Œ Show a nice message when a Shiny app disconnects or errors
R
65
star
14

ddpcr

πŸ”¬ Analysis and visualization of Droplet Digital PCR data in R and on the web
R
60
star
15

daattali.github.io

Dean Attali's website - R/Shiny Consultant
HTML
58
star
16

shinybrowser

🌐 Find out information about a user's web browser in Shiny apps
R
40
star
17

lightsout

πŸ”¦ Lights Out game implemented in R
R
39
star
18

rsalad

A mix of useful R functions that are good for you
R
26
star
19

UBC-STAT545

My first 12 months with R, mostly through a UBC course and my own experiments
HTML
23
star
20

timevisBasic

Helper package to learn advanced 'htmlwidgets' tips
R
22
star
21

gslides-betternotes-extension

The slide previews in the Speaker Notes window of Google Slides are tiny and unreadable. This extension automatically resizes the slides when the window is resized, and allows the user to drag the sidebar to select a size.
JavaScript
21
star
22

statsTerrorismProject

Final project for STAT545A - Terrorist activity data analysis
HTML
20
star
23

github-diff-navigator-extension

Chrome/Firefox extension that allows you to easily navigate through the changes in a file that has been edited on GitHub.
JavaScript
19
star
24

shinytip

πŸ’¬ Simple flexible tooltips for Shiny apps
R
18
star
25

shinyfilebrowser

πŸ“ Simple file browser and list selector for Shiny apps
R
17
star
26

shinymixpanel

πŸ” Track user interactions with Mixpanel in Shiny apps or R scripts
R
13
star
27

rasperry-pi-gaming-console-setup

How to set up raspberry pi as a portable oldies gaming console
13
star
28

cranalerts

Get email alerts when a CRAN package gets updated
R
11
star
29

shiny-mini-workshop

Shiny Mini Workshop
R
9
star
30

single-page-amazon-return-labels-extension

Print Amazon return labels as a single page
JavaScript
9
star
31

settlers-catan-turn-analyzer

Settlers of Catan Turn Analyzer - a simple app to teach myself ReactJS
JavaScript
8
star
32

shinycodeviewer

πŸ“ View and edit a series of code chunks with syntax highlighting in Shiny
R
7
star
33

undomanager

πŸ”„ Generic undo/redo manager for R
R
7
star
34

shiny-colour-gradient-input

Colour gradient input for R-Shiny
R
6
star
35

cashflow-calculation-extension

Cashflow Calculator extension for Zillow, Trulia, and Redfin (works in Chrome/Firefox/Edge)
JavaScript
6
star
36

smileyfy-my-facebook-extension

Chrome extension that adds infinite happiness to your Facebook browsing, plus a little bonus rickrolling :)
JavaScript
5
star
37

shinyHelpers

R
5
star
38

shiny-workshop-odsc2019

Shiny Workshop at ODSC 2019 (visualizing NBA 2018/19 player stats)
R
5
star
39

modularize-addin

RStudio addin to help modularize Shiny app code
R
4
star
40

useR2017

Analysis of useR2017 attendance information
R
3
star
41

bingo

Generate Bingo cards with R.
R
3
star
42

Rlist

Easy way to navigate and explore list structures in R (abandoned project)
R
2
star
43

dash2

R
2
star
44

shiny-training-rstudioconf-2018

R
2
star
45

presentations

A place for me to keep my presentations/papers/etc organized
2
star
46

pftv-ad-bypass-extension

Project Free TV shows an interstitial ad page before allowing users to continue to the video - this extension bypasses that page
JavaScript
2
star
47

attalitech

AttaliTech Ltd
CSS
1
star
48

shinywc

R
1
star
49

shiny-conf-nyr-2022

R
1
star
50

stat540-2014-attali-dean

Lab work for UBC STAT540
R
1
star
51

htmldependencybug

JavaScript
1
star
52

genes-track-demo

HTML
1
star