Spaces:
Sleeping
Sleeping
gordon-posit
commited on
Commit
•
23c719b
1
Parent(s):
2825515
Update to use latest bslib patterns
Browse files
app.R
CHANGED
@@ -7,21 +7,21 @@ 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 <-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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"),
|
22 |
),
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
)
|
26 |
|
27 |
server <- function(input, output, session) {
|
@@ -29,23 +29,30 @@ server <- function(input, output, session) {
|
|
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 |
-
|
42 |
-
|
43 |
-
p <-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
50 |
|
51 |
shinyApp(ui, server)
|
|
|
7 |
# Find subset of columns that are suitable for scatter plot
|
8 |
df_num <- df |> select(where(is.numeric), -Year)
|
9 |
|
10 |
+
ui <- page_sidebar(
|
11 |
+
theme = bs_theme(bootswatch = "minty"),
|
12 |
+
title = "Penguins explorer",
|
13 |
+
sidebar = sidebar(
|
14 |
+
varSelectInput("xvar", "X variable", df_num, selected = "Bill Length (mm)"),
|
15 |
+
varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),
|
16 |
+
checkboxGroupInput("species", "Filter by species",
|
17 |
+
choices = unique(df$Species), selected = unique(df$Species)
|
|
|
|
|
|
|
|
|
18 |
),
|
19 |
+
hr(), # Add a horizontal rule
|
20 |
+
checkboxInput("by_species", "Show species", TRUE),
|
21 |
+
checkboxInput("show_margins", "Show marginal plots", TRUE),
|
22 |
+
checkboxInput("smooth", "Add smoother"),
|
23 |
+
),
|
24 |
+
plotOutput("scatter")
|
25 |
)
|
26 |
|
27 |
server <- function(input, output, session) {
|
|
|
29 |
req(input$species)
|
30 |
df |> filter(Species %in% input$species)
|
31 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
output$scatter <- renderPlot(
|
34 |
+
{
|
35 |
+
p <- ggplot(subsetted(), aes(!!input$xvar, !!input$yvar)) +
|
36 |
+
theme_light() +
|
37 |
+
list(
|
38 |
+
theme(legend.position = "bottom"),
|
39 |
+
if (input$by_species) aes(color = Species),
|
40 |
+
geom_point(),
|
41 |
+
if (input$smooth) geom_smooth()
|
42 |
+
)
|
43 |
+
|
44 |
+
if (input$show_margins) {
|
45 |
+
margin_type <- if (input$by_species) "density" else "histogram"
|
46 |
+
p <- p |> ggExtra::ggMarginal(
|
47 |
+
type = margin_type, margins = "both",
|
48 |
+
size = 8, groupColour = input$by_species, groupFill = input$by_species
|
49 |
+
)
|
50 |
+
}
|
51 |
+
|
52 |
+
p
|
53 |
+
},
|
54 |
+
res = 100
|
55 |
+
)
|
56 |
}
|
57 |
|
58 |
shinyApp(ui, server)
|