Spaces:
Sleeping
Sleeping
Only present numeric columns as options
Browse files
app.R
CHANGED
@@ -4,17 +4,18 @@ library(dplyr)
|
|
4 |
library(ggplot2)
|
5 |
|
6 |
df <- readr::read_csv("penguins.csv")
|
7 |
-
|
|
|
8 |
|
9 |
ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
|
10 |
layout_sidebar(fillable = TRUE,
|
11 |
sidebar(
|
12 |
-
varSelectInput("xvar", "X variable",
|
13 |
-
varSelectInput("yvar", "Y variable",
|
14 |
-
checkboxGroupInput(
|
15 |
-
|
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 |
-
|
42 |
-
|
43 |
-
|
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 |
}
|