hobrien.github.io

Shiny Web Apps

Hello Shiny

library(shiny)
runExample("01_hello")

Anatomy of a Shiny app

ui

server

A simple example

library(shiny)
ui <- fluidPage(
  titlePanel("Hello Shiny!"),
  sidebarLayout(
    sidebarPanel(
      sliderInput(inputId = "bins", label = "Number of bins:", min = 1, max = 50, value = 30)
    ),

    mainPanel(
      plotOutput(outputId = "distPlot")
    )
  )
)

server <- function(input, output) {
  output$distPlot <- renderPlot({
    x    <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    hist(x, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")
    })
}

Additional UI elements:

Additional Server elements:

Performance

dataInput <- reactive({
  getSymbols(input$symb, src = "google",
    from = input$dates[1],
    to = input$dates[2],
    auto.assign = FALSE)
})

output$plot <- renderPlot({    
  chartSeries(dataInput(), theme = chartTheme("white"),
    type = "line", log.scale = input$log, TA = NULL)
})
genotypes <- system(paste("bcftools view -H -r", snp_pos, "./Data/combined_filtered.vcf.gz"), intern=TRUE) %>%
    str_split('\t')

Deployment