How to fit image to fill dashboard card / row / column? #11995
-
DescriptionHello, For a simple dashboard, I'd like to have some of my plots be generated by R code separately (for real-time updates) and then just included as markdown images. I thought that by using the .fill class the contents of each column / row would be resized to fit, but I'm finding that the images are usually overflowing. Is it possible to automatically make the images fit their container? Here's a minimal example: ---
title: "My Dash"
format:
dashboard:
orientation: columns
lightbox:
match: auto
---
## Left Column {width=30%}
Some markdown text here.
- point 1
- point 2
## Right Column {width=70% title=Runs}
### Row 1 {.fill height=60% padding=0%}
![Plot 1](file:Plot01.png){group="plots"}
### Row 2 {.fill}
#### Left {.fill}
![Plot 2](file:Plot02.png){group="plots"}
#### Right {.fill}
![Plot 3](file:Plot03.png){group="plots"}
Here's what it renders to: As you can see, the smaller cards are fitting their images well, but the bigger one loses the bottom part, including the X axis. If I make my winder bigger, I lose the X axis on all of the plots. Is there something I can do to make them fit as expected? Thanks quarto version: 1.6.40 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
I don't recall Also, you are not setting the class on the image itself. |
Beta Was this translation helpful? Give feedback.
-
The .fill class is from the Quarto guide on dashboard layout:
|
Beta Was this translation helpful? Give feedback.
-
For reference: |
Beta Was this translation helpful? Give feedback.
-
Yes, I tried fixing it with CSS but wasn't succeeding. I eventually found a solution - at the bottom of this post. You're right that I was mistaken about quarto's .fill and .padding features. So, in (S)CSS, I tried fixing .img-fluid to have height:100% so that the image would resize to its container. But I found that they still overflowed on the y-axis. So I reverse-engineered how quarto makes code cell contents fit. Here I've replaced one of the placeholder images with a code cell that produces a simple plot. And the output of that plot will scale to fit into its container, while the images do not:
On inspecting the page, I see that the plot image generated by R is contained like so:
However, the simple images have two more containers between them and the "cell-output-display"
So somewhere in the The solution:This is probably not perfect, as it will apply to every figure in the dashboard, and there's probably a way to be more selective, but for now this works: qmd
scss
|
Beta Was this translation helpful? Give feedback.
Yes, I tried fixing it with CSS but wasn't succeeding.
I eventually found a solution - at the bottom of this post.
You're right that I was mistaken about quarto's .fill and .padding features.
So, in (S)CSS, I tried fixing .img-fluid to have height:100% so that the image would resize to its container. But I found that they still overflowed on the y-axis.
So I reverse-engineered how quarto makes code cell contents fit. Here I've replaced one of the placeholder images with a code cell that produces a simple plot. And the output of that plot will scale to fit into its container, while the images do not: