Adam Spannbauer

Data Scientist/Instructor・Mostly write Python & R for pay・Mostly write p5js for fun・Check me out @thespanningset on Instagram

Home

Snake Game Shiny Loader

Published Jan 21, 2018

This post is to share the 🐍snakeLoadR🐍 R package. The package adds the snake game as a loading screen tied to a specific output in a shiny app.

This repo has the code used to make the app in the gif.


This loader package is more of a novelity than it is anything useful, but it was a fun little project. If you’re interested in using the package yourself you can install it using:

devtools::install_github("AdamSpannbauer/snakeLoadR")

To use the snake loader in a shiny app, you need to include the snakeLoadR::snake_loader function in your UI and provide an outputId that the loader will be tied to. The below chunk shows a minimal shiny app using the snake loader.

library(shiny)
library(snakeLoadR)

shinyApp(
  shinyUI(
    fluidPage(
      fluidRow(
        column(width=10, offset=1, algin="left",
               actionButton("my_button", "Start Fake 30 Second Job"),
               uiOutput("my_output")
        )
      ),
      snakeLoadR::snake_loader(outputId = "my_output",
                               header = "Play Snake while you wait!",
                               controls = TRUE)
    )
  ),
  shinyServer(function(input, output) {
    output$my_output <- renderUI({
      if(input$my_button != 0) Sys.sleep(30)
      HTML(paste0("<h3>Fake job completed <code>", input$my_button,"</code> times!</h3>"))
    })
  })
)