rstudio / thematic

Theme ggplot2, lattice, and base graphics based on a few simple settings.
https://rstudio.github.io/thematic/
Other
244 stars 10 forks source link

Auto theming doesn't work with async key caching #56

Closed cpsievert closed 4 years ago

cpsievert commented 4 years ago

Notice how neither of these plots have the right colors (if I run this in RStudio, the plots actually match my RStudio theme). Interestingly, if we set thematic_shiny(bg = "red", fg = "blue", font="auto") (instead of thematic_shiny(font="auto")), you get what you'd expect

library(shiny)
library(promises)
library(thematic)

thematic_shiny(font="auto")

ui <- fluidPage(
  tags$head(
    tags$link(href="https://fonts.googleapis.com/css?family=Patrick Hand", rel="stylesheet"),
    tags$style(HTML("body{background-color:#F0FFF0; color:#8B008B; font-family: Patrick Hand}")),
    tags$style(HTML("a{color:#008000}"))
  ),
  h1("Caching async plots/keys"),
  hr(),
  fluidRow(
    column(6,
           h4("Sync base plot, Async cache key"),
           plotOutput("plotNY")
    ),
    column(6,
           h4("Async base plot, async cache key"),
           plotOutput("plotYY")
    )
  )
)

server <- function(input, output, session) {
  syncPlot <- function() {
    plot(cars)
  }
  asyncPlot <- function() {
    promise_resolve(TRUE) %...>% {
      syncPlot()
    }
  }
  syncKey <- function() {
    Sys.time()
  }
  asyncKey <- function() {
    promise_resolve(syncKey())
  }
  output$plotNY <- renderCachedPlot({
    syncPlot()
  }, cacheKeyExpr = asyncKey())

  output$plotYY <- renderCachedPlot({
    asyncPlot()
  }, cacheKeyExpr = asyncKey())
}

shinyApp(ui, server)
cpsievert commented 4 years ago

This is actually the result of an issue with shiny::getCurrentOutputInfo() https://github.com/rstudio/shiny/issues/3000

MadhulikaTanuboddi commented 4 years ago
143-async-plot-caching-styling_and_fonts_not_applied to third and fourth plots