install.packages('remotes')
remotes::install_github(repo = "mjfrigaard/gap")Shiny frameworks
This website is a resource for Shiny developers to get an ‘under the hood’ view of three popular frameworks.
Golem
Install the gap package using the code below:
Launch the application using:
gap::run_app()Leprechaun
lap: a leprechaun app-package
Install the lap package using the code below:
install.packages('remotes')
remotes::install_github(repo = "mjfrigaard/lap")Launch the application using:
lap::run()Rhino
Source application
The original data and code for each application comes from Building Web Applications With Shiny,2 and I’ve made some small changes to provide a basic (but realistic) example of a monolithic app.R file.
You can download the application movies dataset here.
show/hide movies app
# source: https://rstudio-education.github.io/shiny-course/
# packages ----
library(shiny)
library(shinythemes)
library(ggplot2)
library(tools)
# load data ----
load("movies.RData")
# utility function for plotting ----
scatter_plot <- function(df, x_var, y_var, col_var, alpha_var, size_var) {
ggplot(data = df,
aes(x = .data[[x_var]],
y = .data[[y_var]],
color = .data[[col_var]])) +
geom_point(alpha = alpha_var, size = size_var)
}
# app ----
ui <- fluidPage(
theme = shinytheme("spacelab"),
sidebarLayout(
sidebarPanel(
selectInput(
inputId = "y",
label = "Y-axis:",
choices = c(
"IMDB rating" = "imdb_rating",
"IMDB number of votes" = "imdb_num_votes",
"Critics Score" = "critics_score",
"Audience Score" = "audience_score",
"Runtime" = "runtime"
),
selected = "audience_score"
),
selectInput(
inputId = "x",
label = "X-axis:",
choices = c(
"IMDB rating" = "imdb_rating",
"IMDB number of votes" = "imdb_num_votes",
"Critics Score" = "critics_score",
"Audience Score" = "audience_score",
"Runtime" = "runtime"
),
selected = "critics_score"
),
selectInput(
inputId = "z",
label = "Color by:",
choices = c(
"Title Type" = "title_type",
"Genre" = "genre",
"MPAA Rating" = "mpaa_rating",
"Critics Rating" = "critics_rating",
"Audience Rating" = "audience_rating"
),
selected = "mpaa_rating"
),
sliderInput(
inputId = "alpha",
label = "Alpha:",
min = 0, max = 1,
value = 0.4
),
sliderInput(
inputId = "size",
label = "Size:",
min = 0, max = 5,
value = 3
),
textInput(
inputId = "plot_title",
label = "Plot title",
placeholder = "Enter text to be used as plot title"
),
actionButton(
inputId = "update_plot_title",
label = "Update plot title"
)
),
mainPanel(
br(),
p(
"These data were obtained from",
a("IMBD", href = "http://www.imbd.com/"), "and",
a("Rotten Tomatoes", href = "https://www.rottentomatoes.com/"), "."
),
p(
"The data represent",
nrow(movies),
"randomly sampled movies released between 1972 to 2014 in the United States."
),
plotOutput(outputId = "scatterplot"),
hr(),
p(em(
"The code for this Shiny application comes from",
a("Building Web Applications with shiny",
href = "https://rstudio-education.github.io/shiny-course/"
)
))
)
)
)
server <- function(input, output, session) {
new_plot_title <- reactive({
toTitleCase(input$plot_title)
}) |>
bindEvent(input$update_plot_title,
ignoreNULL = FALSE,
ignoreInit = FALSE
)
output$scatterplot <- renderPlot({
scatter_plot(
# load movies data
df = movies,
x_var = input$x,
y_var = input$y,
col_var = input$z,
alpha_var = input$alpha,
size_var = input$size
) +
labs(title = new_plot_title()) +
theme_minimal() +
theme(legend.position = "bottom")
})
}
shinyApp(ui = ui, server = server)

