Skip to content
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

Default 72 dpi in renderPlot, where the common standard is 96 #25

Closed
cicdguy opened this issue Aug 5, 2021 · 5 comments · Fixed by #26
Closed

Default 72 dpi in renderPlot, where the common standard is 96 #25

cicdguy opened this issue Aug 5, 2021 · 5 comments · Fixed by #26
Assignees

Comments

@cicdguy
Copy link
Contributor

cicdguy commented Aug 5, 2021

Hadley Wickham: I think the correct res is 96 because it ensures that (under typical conditions) 1" on the device is rendered as 1" on screen.

It is not only about going with recommended changes because of common standards. Current resolution of 72 could brings less readable text on our plots.

TODO: Please investigate pros&cons of changing default res. Having plot_with_settings we can specify it in only one place.

Provenance:

Creator: Polkas
@cicdguy
Copy link
Contributor Author

cicdguy commented Aug 5, 2021

Note in teal.devel we explicitly use the "72" to ensure the pdf and svg downloads are the correct size:

type_download_srv <- function(input, output, session, plot_reactive, plot_type, plot_w, default_w, plot_h, default_h) {
  output$data_download <- downloadHandler(
    filename = function() {
      paste(input$file_name, input$file_format, sep = ".")
    },
    content = function(file) {
      width <- if_null(plot_w(), default_w())
      height <- if_null(plot_h(), default_h())

      #svg and pdf have width in inches and 1 inch = 72 pixels
      switch(input$file_format,
        png = png(file, width, height),
        pdf = pdf(file, width / 72, height / 72),
        svg = svg(file, width / 72, height / 72)
      )

NEST/teal.modules.clinical/issues/868

Provenance:

Creator: burkoffn

@cicdguy
Copy link
Contributor Author

cicdguy commented Aug 5, 2021

DPI seems like a rabbit hole, especially if you target consistency across OSs + print.
https://www.r-bloggers.com/2020/04/saving-r-graphics-across-oss/
Personally, I don't see the benefit (yet) of changing DPI given the costs...

However, I'm thinking this info might add value in the upcoming Report generator/ Rmarkdown context:
https://www.r-bloggers.com/2021/02/image-sizes-in-an-r-markdown-document/

Provenance:

Creator: sorinvoicu

@nikolas-burkoff
Copy link
Contributor

nikolas-burkoff commented May 12, 2022

So here is the difference (note graphs are different as the example adds some noise)

library(shiny)
library(ggplot2)

res <- 96 insightsengineering/teal.modules.general#72

shinyApp(
  ui = fluidPage(
    sidebarLayout(
      sidebarPanel(
        actionButton("newplot", "New plot")
      ),
      mainPanel(
        plotOutput("plot")
      )
    )
  ),
  server = function(input, output) {
    output$plot <- renderPlot({
      input$newplot
      # Add a little noise to the cars data
      cars2 <- cars + rnorm(nrow(cars))
      plot(cars2)
    }, res = res)
  }
)

96 dpi:
image

72 dpi:
image

This could easily be a teal option: teal.plot.dpi which by default is either 72 (which is the default to renderPlot) or 96 [ I vote for default as 72 to keep things the same] then in plot_with_settings we have:

  • res = teal.plot.dpi added here
  • replace the hard coded '72' here

And we should update the teal.options vignette to mention this.

@kpagacz @Polkas any impact on teal.reporter here? and does this make sense to do?

@kpagacz
Copy link
Contributor

kpagacz commented May 12, 2022

teal.reporter saves any graphics to a file anyway, so I am unsure of any impact. The saving functions we use have defaults unrelated to rendering (the cursory look at https://ggplot2.tidyverse.org/reference/ggsave.html finds the default dpi to be at 300), and the previewer module presents the saved file as static content, not a rendered plot.

In short - I think there's an impact - users might be confused about small discrepancies between the saved object and the rendered object (so between what they see in a module and the report previewer).

@nikolas-burkoff
Copy link
Contributor

@insightsengineering/nest-core-dev the plan is to do this and this will then handle teal.reporter

Shout if anyone strongly disagrees.

@nikolas-burkoff nikolas-burkoff transferred this issue from insightsengineering/teal.modules.general May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants