Skip to content

Reporting of output styles (colors and fonts) #2740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
May 6, 2020

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jan 17, 2020

Adds the ability to obtain computed CSS styles of output containers via getCurrentOutputInfo() within any renderPlot(), renderImage(), or any output binding with a .shiny-report-theme class. Currently the computed styles include bg (background-color), fg (color), accent (link-color), font (font-family), and renderedFamily (the actual font-family chosen by the browser....this information is only available if FontFaceSet.check() is available). For example:

library(shiny)

shinyApp(
  fluidPage(
    tags$style(HTML("#info {color: #FFFFFF; background-color: #000000}")),
    tags$style(HTML("#info a {color: #00FF00}")),
    h3("Below is computed styles for the info container"),
    tagAppendAttributes(
      textOutput("info"), 
      class = "shiny-report-theme"
    )
  ),
  function(input, output) {
    output$info <- renderText({
      info <- getCurrentOutputInfo()
      jsonlite::toJSON(
        list(
          bg = info$bg(), 
          fg = info$fg(), 
          accent = info$accent(), 
          font = info$font()
        ), 
        auto_unbox = TRUE
      )
    })
  }
)

Screen Shot 2020-05-06 at 12 15 49 PM

Note that after this change, htmlwidgets::shinyWidgetOutput() will gain a reportTheme argument to make it easier for htmlwidgets developers to include the .shiny-report-theme class (and, thus, access styles with getCurrentOutputInfo()).

In addition, a new shiny.useragg option was added to use ragg::agg_png() over Cairo::CairoPNG and non-quartz png() (if ragg is installed). For now, this option will default to FALSE, but will likely default to TRUE in a future release.

Testing notes

Install remotes::install_github("rstudio/shiny"), then run the example app above and confirm that you see the same information as the screenshot. That's ok if you see differences in the font information, but everything else (i.e., bg, fg, accent) should be the same.

There's also a fully automated testing app here https://github.com/rstudio/shinycoreci-apps/blob/master/apps/181-report-theme/app.R

@jcheng5

This comment has been minimized.

@cpsievert cpsievert changed the title renderPlot() auto-coloring based on background and foreground color Plot auto-theming Feb 7, 2020
cpsievert added a commit to cpsievert/htmlwidgets that referenced this pull request Feb 7, 2020
cpsievert added a commit to cpsievert/htmlwidgets that referenced this pull request Feb 9, 2020
@cpsievert cpsievert force-pushed the joe/feature/bs4-compat-plot-colors branch 2 times, most recently from 4d7451f to 3124420 Compare February 18, 2020 19:12
@cpsievert cpsievert marked this pull request as ready for review March 3, 2020 16:34
@cpsievert cpsievert force-pushed the joe/feature/bs4-compat-plot-colors branch from 203707b to 9720270 Compare March 3, 2020 16:49
@cpsievert cpsievert requested a review from wch March 3, 2020 16:50
@cpsievert cpsievert force-pushed the joe/feature/bs4-compat-plot-colors branch from 9367e84 to f2c85b1 Compare March 4, 2020 17:06
@cpsievert cpsievert force-pushed the joe/feature/bs4-compat-plot-colors branch 3 times, most recently from 22bb139 to 0b45628 Compare April 8, 2020 15:47
@cpsievert cpsievert force-pushed the joe/feature/bs4-compat-plot-colors branch 2 times, most recently from 15f87b9 to 2e5c63a Compare April 14, 2020 14:19
@cpsievert cpsievert changed the title Plot auto-theming Reporting of output styles (colors and fonts) Apr 14, 2020
cpsievert added a commit to rstudio/shinycoreci-apps that referenced this pull request May 6, 2020
@cpsievert cpsievert force-pushed the joe/feature/bs4-compat-plot-colors branch from 8215912 to c7f0484 Compare May 6, 2020 18:25
@wch wch merged commit c7a4d23 into master May 6, 2020
cpsievert added a commit to cpsievert/htmlwidgets that referenced this pull request May 6, 2020
jcheng5 pushed a commit to ramnathv/htmlwidgets that referenced this pull request May 6, 2020
* Add reportTheme arg to shinyWidgetOutput(), in anticipation of rstudio/shiny#2740

* Throw message if reportTheme is TRUE and there is an outdated shiny version

* news typo
schloerke added a commit to rstudio/shinycoreci-apps that referenced this pull request May 7, 2020
* master:
  turn it into a full automated test
  text can still appear even if the font is not rendered correctly
  Add a test for png(type='cairo'), ensure Cairo+ragg are installed, re-organize
  flag as manual app
  Add a testing app for rstudio/shiny#2740
@cpsievert cpsievert deleted the joe/feature/bs4-compat-plot-colors branch October 29, 2021 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants