h2oai / wave

Realtime Web Apps and Dashboards for Python and R
https://wave.h2o.ai
Apache License 2.0
3.9k stars 327 forks source link

official example not work #1989

Closed hxmilyy closed 1 year ago

hxmilyy commented 1 year ago

Wave SDK Version, OS

python 3.10.6

Actual behavior

cpu_card.plot_data[-1] = [tick, cpu_usage] the above line give me error: TypeError: 'Data' object does not support item assignment

Expected behavior

no error

below is the example link: https://wave.h2o.ai/docs/tutorial-monitor

help appreciated, i was stucked for a long time

mturoci commented 1 year ago

After discussion at Discord, the cause was getting the wrong reference to the gpu_usage_card.

gpu_usage_card = ui.small_series_stat_card(
            box='1 1 1 1',
            title='CPU',
            value='={{usage}}%',
            data=dict(usage=0.0),
            plot_data=data('tick usage', -15),
            plot_category='tick',
            plot_value='usage',
            plot_zero_value=0,
            plot_color='$red',
)
q.page["home/gpu_stats"] = gpu_usage_card

Instead of

    q.page["home/gpu_stats"] = ui.small_series_stat_card(
        box='1 1 1 1',
        title='CPU',
        value='={{usage}}%',
        data=dict(usage=0.0),
        plot_data=data('tick usage', -15),
        plot_category='tick',
        plot_value='usage',
        plot_zero_value=0,
        plot_color='$red',
    )

    gpu_usage_card = q.page['home/gpu_stats']

or as the tutorial example uses:

cpu_card = page.add('cpu_stats', ui.small_series_stat_card(
    box='1 1 1 1',
    title='CPU',
    value='={{usage}}%',
    data=dict(usage=0.0),
    plot_data=data('tick usage', -15),
    plot_category='tick',
    plot_value='usage',
    plot_zero_value=0,
    plot_color='$red',
))