Quarto & Plotly

R: Prepare data

library(tidyverse)
data <- palmerpenguins::penguins %>% 
  mutate(across(where(is.factor), as.character)) %>% 
  filter(!is.na(sex))
ojs_define(data = transpose(data))

see origin of filtered data_used below

Inputs.table(data_used)

Reactive UI Elements

Species Filter Logic

speciesCount = d3.rollups(data,
  v => v.length,
  d => d.species)
  .map(row => ({Species: row[0], n: row[1]}))

speciesFilter = [...new Set(speciesSelection.map(row => row.Species))]

data_used = speciesFilter.length !== speciesCount.length
  ? data.filter(d => speciesFilter.includes(d.species))
  : data

Species Filter

Stack Toogle

options = ({
  title: `Count of Penguins by Gender & Island (n: ${data_used.length})`,
  barmode: doStack ? "stack" : "group"
})