“Shiny’s WordPress” (John Coene, 2024)
What penguin species has the largest flippers?
Collection of instructions, blocks, from data import to wrangling/visualization.
A transform block:
Instructions:
+
button (top right corner).palmer_penguins
block. You may search in the list.filter_block
, selecting sex
as column and female
as value. Click on run
.ggplot_block
. Select x
and y
wizely.geompoint_block
. You may change shape
and color
.library(shiny)
library(bslib)
library(ggplot2)
library(palmerpenguins)
shinyApp(
ui = page_fluid(
layout_sidebar(
sidebar = sidebar(
radioButtons("sex", "Sex", unique(penguins$sex), "female"),
selectInput(
"xvar",
"X var",
colnames(dplyr::select(penguins, where(is.numeric))),
"body_mass_g"
),
selectInput(
"yvar",
"Y var",
colnames(dplyr::select(penguins, where(is.numeric))),
"flipper_length_mm"
),
selectInput(
"color",
"Color and shape",
colnames(dplyr::select(penguins, where(is.factor))),
"species"
)
),
plotOutput("plot")
)
),
server = function(input, output, session) {
output$plot <- renderPlot({
penguins |>
filter(sex == !!input$sex) |>
ggplot(aes(x = !!input$xvar, y = !!input$yvar)) +
geom_point(aes(color = !!input$color, shape = !!input$color), size = 2)
})
}
)
Changing the data, you also need to change the entire hardcoded server logic!
library(blockr)
1new_stack(
2 data_block = new_dataset_block("penguins", "palmerpenguins"),
filter_block = new_filter_block("sex", "female"),
3 plot_block = new_ggplot_block("body_mass_g", "flipper_length_mm"),
4 layer_block = new_geompoint_block("species", "species")
)
5serve_stack(stack)
Instructions: distribution of age in demo dataset
customdata_block
with demo
as selected dataset.ggplot_block
with x
as func and AGE
as default_columns.geomhistogram_block
(you can leave default settings).labs_block
with title = "Distribution of Age"
, x = "Age (Years)
, y = "Count"
as settings.theme_block
.scalefillbrewer_block
.Collection of recipes (stacks) to build a dashboard.
Instructions:
Add stack
.+
to add a new result_block
.filter_block
to stack 1, with sex
as column and female
as value.ggplot_block
.geom_point block
.Click on Add stack
, then add it a customdata_block
with lab
data.
Click on Add stack
.
customdata_block
with demo
data.join_block
with Stack = "lab_data"
, type = "inner"
, by = c("STUDYID", "USUBJID")
Consider the previous 2 stacks (lab data merged with demo data).
Click on Add stack
, then add a result_block
, targeting the hb_data
stack:
ggplot_block
with x = "VISIT"
and y = "Mean"
as aesthetics.geompoint_block
with func = c("color", "shape")
and default_columns = c("ACTARM", "ACTARM")
.geomerrorbar_block
with ymin = ymin
, ymax = ymax
and color = ACTARM
.geomline_block
with group = ACTARM
and color = ACTARM
.labs_block
with title = "Mean and SD of Hemoglobin by Visit"
, x = "Visit Label"
and y = "Hemoglobin (g/dL)"
.theme_block
, selecting whatever theme you like.