Created
August 10, 2023 15:55
-
-
Save cpsievert/7a93ff167aebf474873493d566ab9e07 to your computer and use it in GitHub Desktop.
Code examples for bslib 0.5.1 announcement blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------ | |
# Learn more about bslib::tooltip() and bslib::popover() at | |
# https://rstudio.github.io/bslib/articles/tooltips-popovers/index.html | |
# ------------------------------------------------------------------------ | |
library(shiny) | |
library(bslib) | |
library(palmerpenguins) | |
library(ggplot2) | |
ui <- page_fillable( | |
card( | |
card_header( | |
"Penguin body mass", | |
tooltip( | |
bsicons::bs_icon("question-circle"), | |
"Mass measured in grams.", | |
placement = "right" | |
), | |
popover( | |
bsicons::bs_icon("gear", class = "ms-auto"), | |
selectInput("yvar", "Split by", c("sex", "species", "island")), | |
selectInput("color", "Color by", c("species", "island", "sex"), "island"), | |
title = "Plot settings", | |
), | |
class = "d-flex align-items-center gap-1" | |
), | |
plotOutput("plt"), | |
card_footer( | |
"Source: Gorman KB, Williams TD, Fraser WR (2014).", | |
popover( | |
a("Learn more", href = "#"), | |
markdown( | |
"Originally published in: Gorman KB, Williams TD, Fraser WR (2014) Ecological Sexual Dimorphism and Environmental Variability within a Community of Antarctic Penguins (Genus Pygoscelis). PLoS ONE 9(3): e90081. [doi:10.1371/journal.pone.0090081](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0090081)" | |
) | |
) | |
) | |
) | |
) | |
server <- function(input, output, session) { | |
output$plt <- renderPlot({ | |
ggplot(penguins, aes(x = body_mass_g, y = !!sym(input$yvar), fill = !!sym(input$color))) + | |
ggridges::geom_density_ridges(scale = 0.9, alpha = 0.5) + | |
coord_cartesian(clip = "off") + | |
labs(x = NULL, y = NULL) + | |
ggokabeito::scale_fill_okabe_ito() + | |
theme_minimal(base_size = 24) + | |
theme(legend.position = "top") | |
}) | |
} | |
shinyApp(ui, server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(bslib) | |
bs_theme_preview( | |
bs_theme(preset = "shiny") | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Quarto + bslib = ❤️" | |
--- | |
```{r} | |
#| echo: false | |
#| message: false | |
library(bslib) | |
library(plotly) | |
card( | |
full_screen = TRUE, | |
card_header("My fullscreen-able plot"), | |
plot_ly(diamonds, x = ~cut, color = ~clarity) | |
) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment