Created
August 29, 2022 14:29
-
-
Save AlbertRapp/3f1e58e9afe182fdc190d2037f5cc70a to your computer and use it in GitHub Desktop.
This is a non-modularized Shiny app to explore different data sets.
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
setwd(here::here('shiny_modules')) | |
library(shiny) | |
library(ggplot2) | |
ui <- fluidPage( | |
theme = bslib::bs_theme( | |
# Colors (background, foreground, primary) | |
bg = 'white', | |
fg = '#06436e', | |
primary = colorspace::lighten('#06436e', 0.3), | |
# Fonts (Use multiple in case a font cannot be displayed) | |
base_font = c('Source Sans Pro', 'Lato', 'Merriweather', 'Roboto Regular', 'Cabin Regular'), | |
heading_font = c('Oleo Script', 'Prata', 'Roboto', 'Playfair Display', 'Montserrat'), | |
font_scale = 1 | |
), | |
tabsetPanel( | |
tabPanel("Penguins", { | |
sidebarLayout( | |
sidebarPanel( | |
selectInput( | |
'select_var_1', | |
'Variable 1', | |
choices = names(palmerpenguins::penguins) | |
), | |
selectInput( | |
'select_var_2', | |
'Variable 2', | |
choices = names(palmerpenguins::penguins) | |
), | |
actionButton( | |
'draw_scatterplot', | |
'Draw scatterplot', | |
) | |
), | |
mainPanel( | |
plotOutput('scatterplot') | |
) | |
) | |
}), | |
tabPanel("Iris", { | |
sidebarLayout( | |
sidebarPanel( | |
selectInput( | |
'select_var_1_iris', | |
'Variable 1', | |
choices = names(iris) | |
), | |
selectInput( | |
'select_var_2_iris', | |
'Variable 2', | |
choices = names(iris) | |
), | |
actionButton( | |
'draw_scatterplot_iris', | |
'Draw scatterplot', | |
) | |
), | |
mainPanel( | |
plotOutput('scatterplot_iris') | |
) | |
) | |
}) | |
) | |
) | |
server <- function(input, output, session) { | |
output$scatterplot <- renderPlot({ | |
ggplot(palmerpenguins::penguins) + | |
geom_point( | |
aes_string(input$select_var_1, input$select_var_2), | |
size = 3, | |
alpha = 0.5, | |
col = 'dodgerblue4' | |
) | |
}) |> bindEvent(input$draw_scatterplot) | |
output$scatterplot_iris <- renderPlot({ | |
ggplot(iris) + | |
geom_point( | |
aes_string(input$select_var_1_iris, input$select_var_2_iris), | |
size = 3, | |
alpha = 0.5, | |
col = 'dodgerblue4' | |
) | |
}) |> bindEvent(input$draw_scatterplot_iris) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment