I’m building a dashboard using Dash, and I’d like to be able to set global styles for the dcc.Graph components - particularly setting the font family, color, size etc. What’s the easiest way to set this for all components?
I’ve tried to add a font={'family': 'New Font'} attribute at various places when the dcc.Graph component is being used, but none of them seem to change the font family for the charts.
The beautiful thing about dash components are that they are essentially dictionary objects which means that they can be copied with minor tweaks to the key: value pairs. Borrowing from this recipe, here is how I’d create a global font for my figures.
Note that using deepcopy is subtle, but necessary. Since layouts are nested dictionaries, we want to make sure that we recursively copy the entire element.
I would like to point out that in some patterns you may want to just apply changes to the layout, therefore this dict-like behavior is extremly useful. You can use maps to filter keys and props you want to inherit from predefined layouts, etc.
For example, the given example with applying only font face and color, and maintaining individual size per figure: