-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] dcc.RangeSlider
tooltip - allow displaying something else than value
#1846
Comments
value
dcc.RangeSlider
tooltip - allow displaying something else than value
I second this feature request. |
Yes please! This is absolutely needed and completely enhances the user experience when working with values such as dates! |
Temp workaround: ie @callback(
hope this helps while request remains open! |
yes we do need this feature, as mentioned by others, this is especially useful for date values. |
Join the issue. Currently, i've added two text components and update them with selected dates. The downside is doing in on a server side is overhead. |
I have the same problem here, this feature can be very useful! |
I second this feature request! I am using a numeric index mapped to a vector of datetimes, and would like to show the datetime as a tooltip (I am using markers=None) instead of numeric index. |
This feature would be very helpful, for now i tinkered with it and tried to find a CSS hack that uses the least amount of callbacks : First, I thought of using tooltips, and updating their content by putting a Second more hacky way but that works in most scenarios : .rc-slider-mark-text {
white-space: nowrap;
display: none;
}
.rc-slider-mark-text-active:nth-child(2),
.rc-slider-mark-text:not(.rc-slider-mark-text-active) + .rc-slider-mark-text-active + .rc-slider-mark-text-active,
.rc-slider-mark-text-active + .rc-slider-mark-text:not(.rc-slider-mark-text-active),
.rc-slider-mark-text-active:last-child {
display: block;
color: #666;
} Shifting to the left is mandatory if you want it to be compatible on most browsers, .rc-slider-mark-text {
white-space: nowrap;
display: none;
}
.rc-slider-mark-text-active:first-child,
.rc-slider-mark-text:not(.rc-slider-mark-text-active) + .rc-slider-mark-text-active,
.rc-slider-mark-text-active:not(:has(~ .rc-slider-mark-text-active)),
.rc-slider-mark-text-active:last-child {
display: block;
color: #666;
} This is a pure front-end solution that works nicely in most usecases where you want to emulate react's Edit, fully functionnal workaround, with usecase :Found out that by fusing the 2 tricks i described earlier, i made it work as i wanted, and here's the code i use to have a date RangeSlider with marks that follow the selected range :
from dash import html, dcc
from dateutil.rrule import rrule, DAILY
from datetime import datetime, timedelta
min_day: datetime
max_day: datetime
day_interval = (max_day - min_day).days
date_range_slider = html.Div(
dcc.RangeSlider(
min=0,
max=day_interval,
value=[0, day_interval],
marks={
i: f'{date - timedelta(days=1):%Y-%m-%d}' for i, date in enumerate(rrule(freq=DAILY, dtstart=min_day, until=max_day))
},
),
style={"--max-tooltip-val": f'"{max_day:%Y-%m-%d}"'}
) Here's the CSS : .rc-slider-mark-text {
white-space: nowrap;
display: none;
}
.rc-slider-mark-text-active:nth-child(2),
.rc-slider-mark-text:not(.rc-slider-mark-text-active) + .rc-slider-mark-text-active + .rc-slider-mark-text-active,
.rc-slider-mark-text-active + .rc-slider-mark-text:not(.rc-slider-mark-text-active),
.rc-slider-mark-text-active:last-child {
display: block;
color: #666;
}
.rc-slider-mark-text-active:last-child {
font-size: 0;
}
.rc-slider-mark-text-active:last-child:before {
content: var(--max-tooltip-val);
font-size: 12px;
} Note that you might wanna move the tooltips a bit to the left (as we take each next tooltip except for the last one), but i let that to your taste. |
I have the same problem. I make a Dash table and on a desktop, all look fine. But if I open my table on a mobile device, the values on my sliders overlap each other. I need a tooltip with a financial format. |
In case anyone is interested i spend some time digging into this with CSS But i did find a solution using JS, it is only possible to format dynamically the value from the slider though. Here is the code that would change values of dates forexample: 20230101 to 2023-01-01
Just add this file to your assets under |
I second this would be very helpful |
In case you need a more robust solution i have improved the code to observe when the tooltip is generated in the body aswell:
|
Is someone still pushing that? Would be a very basic, yet great feature. |
I would also enjoy this feature very much -- want to append a "%" sign to show values as percentages. (Hacked the CSS to use a slider to show performance against a target value -- disabled the slider on the Python side and increased the linewidth of the "track" and "rail". Also need to set the cursor back to default for the slider handle.) EDIT: noticed that this issue was originally for dcc.RangeSlider, not dcc.Slider, but the logic should be almost the same. |
Problem
Currently, the tooltip of
dcc.RangeSlider
can be used to display thevalue
property of the slider. It would be nice if it could display an arbitrary string. E.g. using a dictionary, where keys are thevalue
s of the slider and values are the strings to be displayed in the tooltip.Solution(?)
Apparently, such functionality is present in the react slider.
http://react-component.github.io/slider/?path=/story/rc-slider–handle
See the
tipFormatter
property. Could this property be added todcc.RangeSlider
?Example use-case
Imagine that your slider
value
s are actually indexes of a list of the real values. You want to present the real values to the user instead of the indexes. You cannot use themarks
property of the slider because there are too many values and it would look messy. Thus, you want to use the tooltip to display something else than thevalue
property of the slider.The text was updated successfully, but these errors were encountered: