Customizing the Marks and Values of Sliders

Learn how to customize the layout of the Slider component in the Dash Core Components package.

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:

Get hands-on with 1400+ tech skills courses.