Automatic theming in gganimate using thematic package

Hello everyone, I'm currently learning shiny and I stumbled upon the thematic package, which automatically styles plot outputs in Shiny.

I've been trying to use it to automatically style gganimate plots too, without success, so I'm asking for help here, because I think that it is not even possible. This is a reprex, which shows a static plot automatically styled, and a image output with the animation without styling:

library(shiny)
library(thematic)
library(ggplot2)
library(gganimate)

ui <- fluidPage(
    theme = shinythemes::shinytheme("sandstone"),
    plotOutput("static"),
    imageOutput("dynamic")
)

server <- function(input, output) {
    base_plot <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
                    geom_line() +
                    labs(title = "Title placeholder")
    
    output$static <- renderPlot({
        base_plot
    }, res = 96)
    
    output$dynamic <- renderImage({
        dynamic_plot <- base_plot +
            gganimate::transition_reveal(Sepal.Length)
        
        outfile <- tempfile(fileext = ".gif")
        gganimate::anim_save(
            "outfile.gif",
            gganimate::animate(dynamic_plot,
                               renderer = gganimate::gifski_renderer(),
                               res = 96))
        
        list(src = "outfile.gif",
             contentType = "image/gif")
    }, deleteFile = TRUE)
}

thematic::thematic_shiny(font = "auto")
shinyApp(ui = ui, server = server)

I tried reading the thematic package documentation too, but couldn't find a way to do what I want.

Thanks in advance!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

I hadn't really considered gganimate -- would you mind filing an issue here? https://github.com/rstudio/thematic/issues/new/choose

Also, I'm pretty sure that renderPlot() is working fine, but it's not leading to a noticeable difference because the main colors and fonts of the sandstone theme is not noticeable different from the default. If you to change "sandstone" to "cyborg" the difference will be more obvious.

Thanks, gganimate support is now in the development version of thematic (CRAN release coming soon) remotes::install_github("rstudio/thematic")

1 Like