Skip to content

Commit

Permalink
Upload materials
Browse files Browse the repository at this point in the history
  • Loading branch information
Aimee Gott committed Jan 9, 2019
1 parent 4ddf046 commit 0bb8f51
Show file tree
Hide file tree
Showing 79 changed files with 6,491 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
33 changes: 33 additions & 0 deletions README.md
@@ -1,2 +1,35 @@
# RStudio-Conf-Intermediate-Shiny
Materials for the Intermediate Shiny Workshop at RStudio Conf 2019

## Pre-Installations

In preparation for this workshop you will need a recent version of R and RStudio installed along with all of the following packages:

- cranlogs
- DT
- flexdashboard
- gapminder
- jsonlite
- lubridate
- miniUI
- shiny
- shinyBS
- shinydashboard
- shinyjs
- shinythemes
- shinytoastr
- tidyverse (specifically using dplyr, ggplot2, stringr)

If you are able to, these can be installed using a single package available on GitHub:

remotes::install_github("jcheng5/ShinyWorkshopDeps")
or
devtools::install_github("jcheng5/ShinyWorkshopDeps")

## Materials

During the workshop there will be plenty of opportunity for hands on practice. For these exercises you will need to get a copy of all of the materials, which can be found on GitHub:

https://github.com/aimeegott/RStudio-Conf-Intermediate-Shiny

If you are familiar with GitHub you can clone the repository, or otherwise simply download (you should see a green "Clone or Download" button on the right).
13 changes: 13 additions & 0 deletions RStudio-Conf-Intermediate-Shiny.Rproj
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
24 changes: 24 additions & 0 deletions apps/add-2/add_2.R
@@ -0,0 +1,24 @@
library(shiny)

# Define UI for application that adds 2 to a selected value
ui <- fluidPage(
# Application title
titlePanel("Add 2"),
# Sidebar with a slider input for x
sidebarLayout(
sidebarPanel( sliderInput("x", "Select x", min = 1, max = 50, value = 30) ),
mainPanel( textOutput("x_updated") )
)
)

# Define server logic
server <- function(input, output) {
add_2 <- function(x) { x + 2 }
#current_x <- add_2(input$x)
#output$x_updated <- renderText({ current_x })
current_x <- reactive({ add_2(input$x) })
output$x_updated <- renderText({ current_x() })
}

# Run the application
shinyApp(ui = ui, server = server)
34 changes: 34 additions & 0 deletions apps/adv-reactivity/counter-solution.R
@@ -0,0 +1,34 @@
library(shiny)

# Define UI for counter ---------------------------------------------
ui <- fluidPage(
actionButton("increment", "Increment"),
actionButton("decrement", "Decrement"),
actionButton("reset", "Reset"),

p(
textOutput("value")
)
)

# Define server logic -----------------------------------------------
server <- function(input, output, session) {
rv <- reactiveValues(count = 0)

observeEvent(input$increment, {
rv$count <- rv$count + 1
})
observeEvent(input$decrement, {
rv$count <- rv$count - 1
})
observeEvent(input$reset, {
rv$count <- 0
})

output$value <- renderText({
rv$count
})
}

# Run the app -------------------------------------------------------
shinyApp(ui, server)
22 changes: 22 additions & 0 deletions apps/adv-reactivity/counter.R
@@ -0,0 +1,22 @@
library(shiny)

# Define UI for counter ---------------------------------------------
ui <- fluidPage(
actionButton("increment", "Increment"),
actionButton("decrement", "Decrement"),
actionButton("reset", "Reset"),

p(
textOutput("value")
)
)

# Define server logic -----------------------------------------------
server <- function(input, output, session) {
output$value <- renderText({
0
})
}

# Run the app -------------------------------------------------------
shinyApp(ui, server)
52 changes: 52 additions & 0 deletions apps/adv-reactivity/cranlogs-solution.R
@@ -0,0 +1,52 @@
library(cranlogs)
library(dplyr)
library(lubridate)
library(ggplot2)
library(shiny)

# Define UI for specifying package and plotting cranlogs ------------
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("packages", "Package names (comma separated)"),
actionButton("update", "Update")
),
mainPanel(
plotOutput("plot")
)
)
)

# Define server logic for downloading and parsing cranlogs ----------
server <- function(input, output, session) {

# Parses comma-separated string into a proper vector
packages <- eventReactive(input$update, {
strsplit(input$packages, " *, *")[[1]]
})

# Daily downloads
daily_downloads <- reactive({
cranlogs::cran_downloads(
packages = packages(),
from = "2016-01-01", to = "2016-12-31"
)
})

# Weekly downloads
weekly_downloads <- reactive({
daily_downloads() %>% mutate(date = ceiling_date(date, "week")) %>%
group_by(date, package) %>%
summarise(count = sum(count))
})

# Plot weekly downloads, plus trendline
output$plot <- renderPlot({
ggplot(weekly_downloads(), aes(date, count, color = package)) +
geom_line() +
geom_smooth()
})
}

# Run the app -------------------------------------------------------
shinyApp(ui, server)
53 changes: 53 additions & 0 deletions apps/adv-reactivity/cranlogs.R
@@ -0,0 +1,53 @@
library(cranlogs)
library(dplyr)
library(lubridate)
library(ggplot2)
library(shiny)

# Define UI for specifying package and plotting cranlogs ------------
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("packages", "Package names (comma separated)"),
actionButton("update", "Update")
),
mainPanel(
plotOutput("plot")
)
)
)

# Define server logic for downloading and parsing cranlogs ----------
server <- function(input, output, session) {

# Parses comma-separated string into a proper vector
packages <- reactive({
strsplit(input$packages, " *, *")[[1]]
})

# Daily downloads
daily_downloads <- reactive({
cranlogs::cran_downloads(
packages = packages(),
from = "2016-01-01", to = "2016-12-31"
)
})

# Weekly downloads
weekly_downloads <- reactive({
daily_downloads() %>%
mutate(date = ceiling_date(date, "week")) %>%
group_by(date, package) %>%
summarise(count = sum(count))
})

# Plot weekly downloads, plus trendline
output$plot <- renderPlot({
ggplot(weekly_downloads(), aes(date, count, color = package)) +
geom_line() +
geom_smooth()
})
}

# Run the app -------------------------------------------------------
shinyApp(ui, server)

0 comments on commit 0bb8f51

Please sign in to comment.