Round tooltip value

I am trying to create multiple siders that show the current value (using “tooltip”). Since the division by 10 is not exact the tooltip often shows running 9s or 0s. Is there any way how to round the tooltip value? “template”: f"{value:.4}" works, but only for static values, meaning when I move sliders the initial values do not change.
The code is shown below.
Many thanks in advance.

def update_sliders(lot_wafer):
    row_index = df[df['lotWafer'] == lot_wafer].index[0]
    row_values = df.iloc[row_index][columns]
    
    num_sliders = len(columns)
    num_columns = 5

    sliders_per_column = num_sliders // num_columns
    
    columns = [[] for _ in range(num_columns)]
    
    for idx, col in enumerate(columns):
        mean = means[idx]
        std = stds[idx]
        
        value = np.round(row_values[col], 2)
        min_value, max_value = round_down(df[col].min()), round_up(df[col].max())
        median_value = np.round(df[col].median(), 2)
        
        slider = dcc.Slider(
            id={'type': 'dynamic-slider', 'index': col},
            min=float(min_value),
            max=float(max_value),
            step=(max_value - min_value) / 128,
            value=value,
            marks=None,
            tooltip={"placement": "bottom", "always_visible": True, "template": "{value}"} #
        )
        slider_container = html.Div([html.Label(col), slider], style={'padding': '10px'})
        
        column_index = idx // sliders_per_column
        columns[column_index].append(slider_container)
    
    column_divs = [
        html.Div(
            column, 
            style={
                'display': 'flex', 
                'flex-direction': 'column', 
                'flex': '1 0 20%'
            }
        ) 
        for column in columns
    ]
    
    grid = html.Div(
        column_divs, 
        style={
            'display': 'flex', 
            'flex-direction': 'row',
            'justify-content': 'space-around'
        }
    )
    
    return grid

Hey @alex_ko welcome to the forums.

Does this help?

1 Like

Yes!!! Thanks a ton!

1 Like