Spaces:
Runtime error
Runtime error
File size: 989 Bytes
62d233e 6628ae0 62d233e 242bfc3 62d233e 6628ae0 62d233e e1e51f5 62d233e e1e51f5 62d233e e1e51f5 6628ae0 62d233e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
library(shiny)
library(bslib)
library(dplyr)
library(ggplot2)
df <- readr::read_csv("penguins.csv")
# Find subset of columns that are suitable for scatter plot
df_num <- df |> select(where(is.numeric), -Year)
ui <- page_fillable(
theme = bs_theme(bootswatch = "minty"),
layout_sidebar(
sidebar(
varSelectInput("xvar", "X variables", df_num, selected = "Bill Length (mm)"),
varSelectInput("yvar", "Y variables", df_num, selected = "Bill Depth (mm)"),
checkboxGroupInput("species", "Filter by species",
choices = unique(df$Species), selected = unique(df$Species)
)
),
plotOutput("scatter")
)
)
server <- function(input, output, session) {
subsetted <- reactive({
req(input$species)
df |> filter(Species %in% input$species)
})
output$scatter <- renderPlot({
p <- ggplot(subsetted(), aes(.data[[input$xvar]], .data[[input$yvar]])) +
theme(legend.position = "bottom")
p
})
}
shinyApp(ui, server)
|