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

Problem with Shiny implementation due to loss of font proportions when resizing #70

Open
barabas14 opened this issue Feb 25, 2025 · 2 comments

Comments

@barabas14
Copy link

Description

Thanks for tidyplots, great and easy to use! However, I have a Shiny app where I want to place my plot and it should resize/rescale depending on the size of the box it is placed, or when changing screen sizes. The problem is that when setting width and height to NA, the graph does not keep the proportions for the fonts, point size, etc.

I know this is something that has been commented before, but is there any intention to fix it to make tidyplots more compatible with Shiny? It would be great if it could work!

Thanks in advance!

@jbengler
Copy link
Owner

jbengler commented Feb 26, 2025

Hi @barabas14

Thank you for using tidyplots!

The way I see this problem

In tidyplots, I chose to use absolute dimensions, e.g. with = 50, height = 50, as a default to preserve proportions. This can be considered an exotic choice in the ecosystem, because the longstanding default is to use free dimensions, e.g. width = NA, height = NA.

Therefore, tools like RStudio, Positron, RMarkdown, Quarto and Shiny are currently not designed to work with absolute dimensions out of the box. There is little tidyplots can do about this, other than providing the fallback to free dimensions using width = NA, height = NA.

What is the way forward?

  1. There might be workarounds in these tools to still work reasonably well with absolute dimensions. For example, in RMarkdown and Quarto you can manually adjust the figure width and height in the chunk options to get good results.
    https://bookdown.org/yihui/rmarkdown-cookbook/figure-size.html
    https://quarto.org/docs/computations/execution-options.html#figure-options

  2. If absolute dimensions get sufficiently popular, the developer of these tools might choose to provide built-in support in the future.

Back to your question regarding Shiny

I quickly tried to use tidyplots in a Shiny app. However, the results were not satisfactory. I basically had to give up absolute dimension to get it to work properly. I have to admit that I am not very experienced with Shiny, so there might definitely be ways to get it to work.

My approach would be to produce a plot output file with little white space around the plot and then make this <img> "responsive" in the sense that it expands to fill the available space.
https://www.w3schools.com/howto/howto_css_image_responsive.asp

Currently, I do not have the capacity to research this in detail. But I will let you know in case I come across a solution.

Best
Jan

@jbengler
Copy link
Owner

I opened a feature request regarding this topic over at the shiny repo.
rstudio/shiny#4194

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

No branches or pull requests

2 participants