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!