| 1 |
library(shiny) |
| 2 |
library(ggplot2) |
| 3 |
library(ggthemes) |
| 4 |
library(thematic) |
| 5 |
library(dplyr) |
| 6 |
library(showtext) |
| 7 |
library(Cairo) |
| 8 |
library(bslib) |
| 9 |
|
| 10 |
|
| 11 |
ui <- fluidPage( |
| 12 |
theme = bs_theme(bootswatch = "darkly"), |
| 13 |
selectInput( |
| 14 |
"theme", "Choose a theme", |
| 15 |
choices = grep("^theme_", getNamespaceExports("ggthemes"), value = TRUE) |
| 16 |
), |
| 17 |
fluidRow( |
| 18 |
column(6, tags$h4("Before thematic"), plotOutput("theme_off")), |
| 19 |
column(6, tags$h4("After thematic"), plotOutput("theme_on")) |
| 20 |
), |
| 21 |
verbatimTextOutput("cache") |
| 22 |
) |
| 23 |
|
| 24 |
p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + |
| 25 |
geom_point() |
| 26 |
|
| 27 |
server <- function(input, output, session) { |
| 28 |
|
| 29 |
observe({ |
| 30 |
theme_fun <- match.fun(input$theme) |
| 31 |
theme_set(theme_fun()) |
| 32 |
}, priority = 2) |
| 33 |
|
| 34 |
output$theme_on <- renderPlot({ |
| 35 |
input$theme |
| 36 |
thematic_with_theme(thematic_theme(font = "Pacifico"), print(p)) |
| 37 |
}) |
| 38 |
|
| 39 |
output$theme_off <- renderPlot({input$theme; print(p)}) |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
shinyApp(ui, server) |