Search⌘ K
AI Features

Customizing the Marks and Values of Sliders

Explore how to customize slider marks and values in Dash by using dictionaries for labels and applying CSS styling for clarity and distinction. Understand how to leverage color scales like cividis to enhance visual consistency, create multiple sliders with thoughtful default values and marks, and connect these controls with charts through callback functions. This lesson equips you to implement interactive, user-friendly sliders that improve dashboard functionality and engagement.

Let’s now create the marks for our slider.

Creating marks

The simplest way to create these is by using a dictionary: {0: '$1.9', 1: '$3.2', 2: '$5.5'}. These keys will be used as the value attribute, and the values of the dictionary are what the user will see for each poverty level. This will suffice for our case, and we can use it as such.

We optionally have the chance to customize the style of our labels, which can take any CSS attribute as a dictionary. If we look at working example in the previous lesson, we can see that the marks (numbers) of the two sliders have a very light color, and they might give the impression that they belong to the same slider. We can improve this by setting their colors to a dark color. We can also set a bold font for the indicator slider. This will help distinguish them from the years, and it will also emphasize their uniqueness. Years are easy to immediately grasp, but users are most likely not familiar with the levels of poverty tracked in the dataset.

We want to get a color that is consistent with our charts. And since we will be using the cividis color scale, it’s a good opportunity to get to know how we can extract its colors. The px.colors.sequential module contains, among other things, lists of the colors of the sequential color scales. We can get cividis by running the following command:

C++
import plotly.express as px
print(px.colors.sequential.Cividis)

The list we receive contains the ten colors that are actually used to construct this scale. Recall that we tried this manually with two and three colors. It’s also interesting to know that we can get the reversed version of a scale by appending ...