To enable {thematic} for every plotOutput() inside a Shiny app, call thematic_shiny() before launching the app.
By default, thematic_shiny() uses the app's CSS colors to inform R plotting defaults. If your app uses Google Fonts and you have {showtext} or {ragg} installed, you can pass font = "auto" to thematic_shiny() to translate CSS fonts to R fonts.
Note: If you want {ragg} to handle font rendering in Shiny, set options(shiny.useragg = TRUE).
library(shiny)
library(ggplot2)
library(thematic)
library(ragg)
# Enable ragg for font rendering
options(shiny.useragg = TRUE)
# Enable thematic for the Shiny app
thematic_shiny(font = "auto")
ui <- fluidPage(
theme = bslib::bs_theme(
bg = "#002B36", fg = "#EEE8D5", primary = "#2AA198",
base_font = bslib::font_google("Pacifico")
),
tabsetPanel(
type = "pills",
tabPanel("ggplot", plotOutput("ggplot")),
tabPanel("lattice", plotOutput("lattice")),
tabPanel("base", plotOutput("base"))
)
)
server <- function(input, output) {
output$ggplot <- renderPlot({
ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars), color = factor(cyl))) +
geom_point() +
ggrepel::geom_text_repel()
})
output$lattice <- renderPlot({
lattice::show.settings()
})
output$base <- renderPlot({
image(volcano, col = thematic_get_option("sequential"))
})
}
shinyApp(ui, server)