Package installation

install.packages('shiny', 'portalr')

Starting a new App

Running the App

Basic structure

Our project

UI

titlePanel("Portal Rodent Species Dynamics")

Loading data

library(portalr)
library(dplyr)
library(ggplot2)

abundances <- abundance(shape = "long", time = "date", clean = FALSE)
species_list <- unique(abundances$species)

Changing Sidebar

selectInput("species",
            "Species",
            species_list)

Server

Changing the graph

output$distPlot <- renderPlot({
    filtered_abundances <- abundances %>% 
      filter(species == input$species)
    ggplot(filtered_abundances, aes(x = censusdate, y = abundance)) +
      geom_line()

Selecting multiple species

selectInput("species",
            "Species",
            species_list,
            multiple = TRUE)
filter(species %in% input$species)
ggplot(filtered_abundances, aes(x = censusdate, y = abundance, color = species))

Change the date range

min_date <- min(abundances$censusdate)
max_date <- max(abundances$censusdate)
sliderInput("dates",
            "Date Range",
            min = min_date,
            max = max_date,
            value = c(min_date, max_date))
filter(censusdate >= input$dates[1], censusdate <= input$dates[2])

Sharing your app

shiny::runGitHub('portal-explorer', 'weecology')

https://ethanwhite.shinyapps.io/portal-explorer/

Add an optional smoother (optional extension for longer time-periods)

checkboxInput("smoother", 
            "Smoother")
ts_plot <- ggplot(filtered_abundances, aes(x = censusdate, y = abundance, color = species)) +
    geom_line()
if (input$smoother){
    ts_plot <- ts_plot + geom_smooth()