shinylive

Author

Paul Campbell

shinylive allows for ‘serverless’ deployment of shiny apps. The front-end UI connects to a WebR server session, both loaded in the user’s browser.

Below you can edit the app code in the editor on the left and re-launch the live app with your changes in the viewer on the right.

#| standalone: true
#| components: [editor, viewer]
#| viewerHeight: 400

# load packages
library(shiny)
library(bslib)
library(outbreaks)
library(ggplot2)
library(incidence2)

# load data
ebola <- ebola_sim_clean$linelist
intervals <- c("daily", "isoweek", "epiweek", "monthly", "quarterly", "yearly")

# define user interface
ui <- page_fillable(
  card(
    card_header("Incidence"),
    card_body(
      div(
        class = "d-flex justify-content-start",
        selectInput("interval", "Interval", choices = intervals),
        selectInput("group", "Group", choices = c("gender", "outcome"))
      ),
      plotOutput("plot") 
    )
  )
)

# define server function
server <- function(input, output, session) {
  inci <- reactive({
    incidence(
      ebola, 
      date_index = "date_of_onset", 
      groups = input$group,
      interval = input$interval
    )
  })
  output$plot <- renderPlot({
    plot(inci(), fill = isolate(input$group))
  })
}

# launch the app
shinyApp(ui = ui, server = server)