jcheng5 commited on
Commit
1392349
·
1 Parent(s): 03bc916

Only present numeric columns as options

Browse files
Files changed (1) hide show
  1. app.R +11 -14
app.R CHANGED
@@ -4,17 +4,18 @@ library(dplyr)
4
  library(ggplot2)
5
 
6
  df <- readr::read_csv("penguins.csv")
7
- species <- unique(df$Species)
 
8
 
9
  ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
10
  layout_sidebar(fillable = TRUE,
11
  sidebar(
12
- varSelectInput("xvar", "X variable", df, selected = "Bill Length (mm)"),
13
- varSelectInput("yvar", "Y variable", df, selected = "Bill Depth (mm)"),
14
- checkboxGroupInput(
15
- "species", "Filter by species", species, selected = species
16
  ),
17
- hr(),
18
  checkboxInput("by_species", "Show species", TRUE),
19
  checkboxInput("show_margins", "Show marginal plots", TRUE),
20
  checkboxInput("smooth", "Add smoother"),
@@ -38,15 +39,11 @@ server <- function(input, output, session) {
38
  )
39
 
40
  if (input$show_margins) {
41
- p <- ggExtra::ggMarginal(
42
- p,
43
- type = if (input$by_species) "density" else "histogram",
44
- margins = "both",
45
- size = 8,
46
- groupColour = input$by_species,
47
- groupFill = input$by_species
48
- )
49
  }
 
50
  p
51
  }, res = 100)
52
  }
 
4
  library(ggplot2)
5
 
6
  df <- readr::read_csv("penguins.csv")
7
+ # Find subset of columns that are suitable for scatter plot
8
+ df_num <- df |> select(where(is.numeric), -Year)
9
 
10
  ui <- 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 rule
19
  checkboxInput("by_species", "Show species", TRUE),
20
  checkboxInput("show_margins", "Show marginal plots", TRUE),
21
  checkboxInput("smooth", "Add smoother"),
 
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
  p
48
  }, res = 100)
49
  }