Coder Social home page Coder Social logo

xiangnandang / shinycssloaders Goto Github PK

View Code? Open in Web Editor NEW

This project forked from daattali/shinycssloaders

0.0 0.0 0.0 144 KB

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

Home Page: https://daattali.com/shiny/shinycssloaders-demo/

R 36.34% CSS 58.96% JavaScript 4.70%

shinycssloaders's Introduction

shinycssloaders

CRAN Travis build status

Add loader animations (spinners) to Shiny Outputs (e.g. plots, tables). Loading animations leverage on Shiny JS events and will show whilst the output value is not yet available or is 'out-of-date' (i.e. has been invalidated and the client hasn't received the new value). The spinners won't show if the output is not rendered (e.g. a validate or req is preventing it from being shown).

The advantages of using this package are:

  • Automatic spinner showing / hiding. Just add one extra R function call (see below) and your output will have the spinner showing at just the right times
  • Customizeable spinner color (for each output or globally)
  • Customizeable spinner size (for each output or globally)
  • Choose from 8 different well-designed spinner types

The CSS animations are bundled from https://projects.lukehaas.me/css-loaders/, where you can see how they appear.

You can use it for any type of shiny output, by wrapping the UI element with the withSpinner tag:

# load the library
library(shinycssloaders)

...

withSpinner(plotOutput("my_plot")) 
# if you have `%>%` loaded, you can do plotOutput("my_plot") %>% withSpinner()

...

For outputs with uknown heights (e.g. tables), a 'proxy' container will be inserted, as the spinner cannot be centered with respect to a height that is uknown to the client (e.g. you might return a really large / small table, who knows?). By default the proxy container will be of height '400px', however if your output is expected to be substantially larger / smaller, you can adjust this with proxy.height option.

Installation

The package is now available on CRAN, however for the latest (and hopefully greatest!) version you can use the devtools package to install it from github directly:

devtools::install_github('daattali/shinycssloaders')

Demo

To see how this works in action, you can check my example on shinyapps.io or - in case my free shinyapps monthly allowance is over - run the example application from github directly:

shiny::runGitHub('daattali/shinycssloaders', subdir = "inst/examples/basic")

To see how the spinner works for outputs with undefined height, you can check out this example or run it from github directly:

shiny::runGitHub('daattali/shinycssloaders', subdir = "inst/examples/table")

Changing the spinner color

You can specify a spinner color for each output or set a variable globally.

Locally for each output

Just add color attribute to withSpinner:

plotOutput("my_plot") %>% withSpinner(color="#0dc5c1")

Globally

You can use options(spinner.color="#0dc5c1") to set the global color.

Background color

Spinner types 2-3 require you to specify a background color as well, which should match the background color of the container hosting the output. The other spinners work automatically without having to specify a background color.

Changing the spinner size

The spinners scale in a relative fashion by specifying the size argument of withSpinner (default value is 1, so if you need to double the spinner for example, set size to 2). You can also set the size globally using options(spinner.size=my_size).

shinycssloaders's People

Contributors

andrewsali avatar daattali avatar steamtraen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.