CoolFace
Apppublic

alsaunders/SemanticSearchAPI

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.R52 linesDownload Raw Back to root
1library(shiny)2library(bslib)3library(dplyr)4library(ggplot2)5 6df <- readr::read_csv("penguins.csv")7# Find subset of columns that are suitable for scatter plot8df_num <- df |> select(where(is.numeric), -Year)9 10ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),11  layout_sidebar(fillable = TRUE,12    sidebar(13      varSelectInput("xvar", "X variable", df_num, selected = "Bill Length (mm)"),14      varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),15      checkboxGroupInput("species", "Filter by species",16        choices = unique(df$Species), selected = unique(df$Species)17      ),18      hr(), # Add a horizontal rule19      checkboxInput("by_species", "Show species", TRUE),20      checkboxInput("show_margins", "Show marginal plots", TRUE),21      checkboxInput("smooth", "Add smoother"),22    ),23    plotOutput("scatter")24  )25)26 27server <- function(input, output, session) {28  subsetted <- reactive({29    req(input$species)30    df |> filter(Species %in% input$species)31  })32  33  output$scatter <- renderPlot({34    p <- ggplot(subsetted(), aes(!!input$xvar, !!input$yvar)) + list(35      theme(legend.position = "bottom"),36      if (input$by_species) aes(color=Species),37      geom_point(),38      if (input$smooth) geom_smooth()39    )40 41    if (input$show_margins) {42      margin_type <- if (input$by_species) "density" else "histogram"43      p <- p |> ggExtra::ggMarginal(type = margin_type, margins = "both",44        size = 8, groupColour = input$by_species, groupFill = input$by_species)45    }46    47    p48  }, res = 100)49}50 51shinyApp(ui, server)52