
“Shiny’s WordPress” (John Coene, 2024)
What penguin species has the largest flippers?

Collection of instructions, blocks, from data import to wrangling/visualization.
flowchart TD
blk_data_in(Input data)
blk_data_out[Output]
subgraph blk_block[Transform block]
blk_field1(Field 1)
blk_field2(Field 2)
blk_field1 --> |interactivity| blk_expr
blk_field2 --> |interactivity| blk_expr
blk_expr(Expression)
blk_res(result)
blk_expr --> |evaluate| blk_res
end
blk_data_in --> blk_block --> blk_data_out
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.flowchart TD
subgraph LR workspace[Workspace]
subgraph stack1[Stack]
direction LR
subgraph input_block[Block 1]
input(Data: dataset, browser, ...)
end
subgraph transform_block[Block 2]
transform(Transform block: filter, select ...)
end
subgraph output_block[Block 3]
output(Result/transform: plot, filter, ...)
end
input_block --> |data| transform_block --> |data| output_block
end
subgraph stack2[Stack 2]
stack1_data[Stack 1 data] --> |data| transform2[Transform]
end
stack1 --> |data| stack2
subgraph stackn[Stack n]
stacki_data[Stack i data] --> |data| transformn[Transform] --> |data| Visualize
end
stack2 ---> |... data| stackn
end
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.