Skip to content

Instantly share code, notes, and snippets.

@Brandon-Rozek
Created May 15, 2021 00:03
Show Gist options
  • Save Brandon-Rozek/9db8414fed1eb1f175ccda32d3fdaaab to your computer and use it in GitHub Desktop.
Save Brandon-Rozek/9db8414fed1eb1f175ccda32d3fdaaab to your computer and use it in GitHub Desktop.
R Script to showcase different themes using sample data in a shiny app
library(shiny)
library(dplyr)
library(ggplot2)
library(GGally)
library(ggthemr)
library(gapminder)
gapminder_mediangdp = gapminder %>%
group_by(year, continent) %>%
summarize(medianGdp = median(gdpPercap))
# Define UI for application that plots features of movies
ui <- fluidPage(
plotOutput(outputId = "plot", height = 600),
hr(),
# Select input for theme
selectInput(inputId = "theme",
label = "Theme:",
choices = c("flat", "flat dark", "dust",
"light", "earth", 'fresh',
'chalk', 'lilac', 'carrot',
'pale', 'copper', 'grape',
'greyscale', 'sky', 'solarized',
'grass', 'sea', 'camoflauge'),
selected = 'flat dark')
)
# Define server function required to create the scatterplot
server <- function(input, output) {
# Create plot
output$plot <- renderPlot({
ggthemr(input$theme, type = 'outer')
# ggplot(data = gapminder_mediangdp, aes(x = year, y = medianGdp, color = continent)) +
# geom_line(size = 2)
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, color = continent, size = pop)) +
geom_point() +
scale_x_log10() +
facet_wrap(~year)
#ggpairs(subset(gapminder, select = -country))
})
}
# Create a Shiny app object
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment