Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aimee Gott
committed
Jan 9, 2019
1 parent
4ddf046
commit 0bb8f51
Showing
79 changed files
with
6,491 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Oops, something went wrong.