knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(easyshiny)
library(shiny)
library(ggplot2)
es_init()

Easyshiny

Easyshiny is a package, that implements a shiny template for uploading and visualizing data. It tries to make the fill out process for this template as easy as possible. The goal is to make the difference between plotting data and showing it in a shiny app very small.

Basic functions

To build the most barebone easyshiny app you need the following commands:

library(easyshiny)

es_init()
es_start(title = 'Your title')

This builds a shinydashboard app with only an input tab. This tab can be used to upload data, but the data won't be used anywhere. To gain control over the uploaded files insert this between the statements above:

es_read('bike_buyers.csv')

es_renderPlot(
  { 
    ggplot(bike_buyers(), aes(x=Commute.Distance, fill=Purchased.Bike)) +
    geom_bar(position = 'fill')
  }, 
  tab = 'Bikes', 
  box = 'Visualization'
)

This tells the app to expect a bike_buyers.csv file for further processing. It builds a reactive expression (See: shiny) that returns a dataframe. The expression can for example be used to build plots with the es_renderPlot function. The function takes a code chunk, that creates a plot and also a corresponding tab and box inside the apps structure can be defined.

Additionally input objects can be defined via es_add_input and used in shiny fashion. An example is shown below.

es_add_input(
  sliderInput,
  inputId = "agespan",
  label='choose an agespan:',
  min=0,
  max=90,
  value=c(0,90),
  tab = 'Bikes',
  box = 'Visualization'
)

es_renderPlot(
  {
    ggplot(
      bike_buyers() %>% filter(Age >= input$agespan[1] & Age <= input$agespan[2]),
      aes(x=Age, y=Income)) +
        geom_point() +
        geom_smooth()
  }, 
  tab = 'Bikes', 
  box = 'Visualization'
)

If you want to include static HTML elements to the app, the function es_add_static has you covered. It understands all the static element creators defined in Shiny. Use it like so:

es_add_static( 
  tags$p('This is a paragraph.', strong('With a nested part inside')), 
  tab = 'Bikes',
  box = "Visualization"
)

As you can see, The elements can be nested of course. Keep in mind, that all created objects will be placed in the corresponding boxes in the order of their definition.

This concludes the main features up until now. The whole app would be looking like this:

es_init()

es_read('bike_buyers.csv')

es_renderPlot(
  { 
    ggplot(bike_buyers(), aes(x=Commute.Distance, fill=Purchased.Bike)) +
    geom_bar(position = 'fill')
  }, 
  tab = 'Bikes', 
  box = 'Visualization'
)

es_add_static( 
  tags$p('This is a paragraph.', strong('With a nested part inside')), 
  tab = 'Bikes',
  box = "Visualization"
)

es_add_input(
  sliderInput,
  inputId = "agespan",
  label='choose an agespan:',
  min=0,
  max=90,
  value=c(0,90),
  tab = 'Bikes',
  box = 'Visualization'
)

es_renderPlot(
  {
    ggplot(
      bike_buyers() %>% filter(Age >= input$agespan[1] & Age <= input$agespan[2]),
      aes(x=Age, y=Income)) +
        geom_point() +
        geom_smooth()
  }, 
  tab = 'Bikes', 
  box = 'Visualization'
)

es_start(title = 'Your title')

If you want to test the app itself use:

system.file("extdata", "bike_buyers.csv", package = "easyshiny")

as example upload data.



mYstar/easyshiny documentation built on June 21, 2019, 10:37 a.m.