Custom labels on DAQ components

Is there any way to customise labels on DAQ components such as the Gauge and Knob?
I’d like to show text labels instead of numbers. Or even hide labels entirely.

I had a look at the APIs for those, but there didn’t seem to be anything obvious…

I haven’t tested this, but my guess is that the scale property can be used for this on both Knob and Gauge.

From the documentation:
scale is a dict with keys:

  • custom (dict; optional): Custom scale marks. The key determines the position and the value determines what will show. If you want to set the style of a specific mark point, the value should be an object which contains style and label properties.custom is a number | dict with keys:
    • label (string; optional)
    • style (string; optional)
1 Like

HI @Wabiloo
@yanboe is correct. You would have to use the custom property here:

from dash import Dash, dcc, html, Input, Output
import dash_daq as daq

app = Dash(__name__)

app.layout = html.Div([
    daq.Gauge(
        id='my-gauge-1',
        value=6,
        scale={'custom':{5:'five', 6:'six', 7:'seven'}}
    ),
    dcc.Slider(
        id='my-gauge-slider-1',
        min=0,
        max=10,
        step=1,
        value=6
    ),
])

@app.callback(Output('my-gauge-1', 'value'), Input('my-gauge-slider-1', 'value'))
def update_output(value):
    return value

if __name__ == '__main__':
    app.run_server(debug=True)

1 Like

Would it be too difficult to demonstrate a Callback that updates the scale so that new custom key & values are created?
I’ve tried several attempts and seem stuck.

hi @Mr.King
:wave: welcome to the community.

Can you please say more. How would you like the scale to update? For what purpose? How often?

I am using the gauge to show technicians the hours until Maintenance.
We have Minor Maintenance and Major Maintenance.
For example, Minor occurs every 1100 hours and Major at 4000 hours.
(Those numbers will change based on tool type)
So the Scale will look something like:

scale = {'custom':{ minor: 'Minor Mnt',  major: 'Major Mnt"}}

minor & major are the unique values I pull from the DataFrame when filtered for a specific tool.

dbc.Row(
            [
                html.P('Clean Cycle'),
                html.Div(
                    daq.Gauge(
                        id='clean-gauge',
                        value=0,
                        label="Maintenance Hours",
                        showCurrentValue=True,
                        scale={'custom':{5:'five', 6:'six', 7:'seven'}}
                    )

@callback(Output('clean-gauge', 'scale'),
         [Input('steps', 'data'),
          Input('pets', 'data'),
         ])
def sidegauge(steps_val, pets_val): 
    if pets_val is None:
        raise PreventUpdate

    pets = json.loads(pets_val)
    steps_df = pd.DataFrame(steps_val)

    fullim, minlim = times.sidetimes(steps_df, pets)

    fullim=fullim.astype(int)
    minlim=minlim.astype(int)

    scale={minlim:'Mini PM', fullim:'Full PM'}

    return scale

error:
dash.exceptions.InvalidCallbackReturnValue: The callback for <Output clean-gauge.scale>
returned a value having type dict
which is not JSON serializable.

hi @Mr.King
I’m not too sure what the ‘steps’ and ‘pets’ stand for. But the scale component has a ‘custom’ key. What happens when you include that in the returned object?

scale={'custom':{minlim:'Mini PM', fullim:'Full PM'}}
return scale

Hi Adam, (its nice that when I read your messages I can hear your voice because watching most of your youtube content)

The result of using below is the same error message.
scale={‘custom’:{minlim:‘Mini PM’, fullim:‘Full PM’}}
return scale

‘steps’ & ‘pets’ are the df and filters i have called from dcc.Store()
minlim & fullim are integers.

I think my problem is unpacking this nested dictionary.
I also don’t understand how if it gets JSON serialized(like string) that it returns to Dictionary to update the Gauge scale.

With some help from Adam I figured out the error.
The integers I had in my dictionary were data type numpy.int64
Once I changed them to normal python data type integer then it worked as expected.

To convert numpy.int64 to python integer:

minlim= minlim.item()

1 Like