pythonquarto

How to assign a RGB background color to a Quarto dashboard valuebox?


Consider the following quarto dashboard:

---
title: "Test"
format: dashboard
---

```{python}
#| content: valuebox
#| title: "Test Box"
dict(value=10, color="red") 
```

enter image description here

How can I define the background color of the valuebox dynamically using RGB colors? I am probably missing the correct syntax.

Doing it like this doesn't lead to the expected result:

---
title: "Test"
format: dashboard
---

```{python}
#| content: valuebox
#| title: "Test Box"
dict(value=10, color="background-color: rgb(255,0,0)") 
```

enter image description here


Solution

  • You can convert the rgb values to hex:

    ---
    title: "Test"
    format: dashboard
    ---
    
    ```{python}
    #| content: valuebox
    #| title: "Test Box"
    dict(value=10, color='#%02x%02x%02x' % (255, 0, 0))
    ```
    

    enter image description here