Skip to content
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

Avoid having to specify pack=True when using data() for components #441

Closed
mtanco opened this issue Dec 22, 2020 · 1 comment · Fixed by #2085
Closed

Avoid having to specify pack=True when using data() for components #441

mtanco opened this issue Dec 22, 2020 · 1 comment · Fixed by #2085
Assignees
Labels
feature Feature request py Related to Python Driver

Comments

@mtanco
Copy link
Contributor

mtanco commented Dec 22, 2020

Question and Background

It seems to the developer that 1. ui.form_card with ui.visualization would be the same as 2. ui.plot_card. This is not explicitly stated in the docs, but from looking at examples it seems like 1. is the only way to replicate 2. in a card with other items, so the user assumes you could copy-past your plot and data code from one and put it in the other. This is not the case when using a dataframe, and addition option pack=True is required in 1.

Reproducible Example

n = 100
    df = pd.DataFrame({'length': np.random.rand(n),
                       'width': np.random.rand(n),
                       'data_type': np.random.choice(a=['Train', 'Test'], size=n, p=[0.8, 0.2])
                       })

    plot_marks = [ui.mark(type='point', x='=length', x_title='Length (cm)', y='=width', y_title='Width (cm)',
                          color='=data_type', shape='circle')]

    q.page['scatter_plot_card'] = ui.plot_card(
        box='1 1 4 4',
        title='Scatter Plot from Dataframe',
        data=data(
            fields=df.columns.tolist(),
            rows=df.values.tolist()
        ),
        plot=ui.plot(marks=plot_marks)
    )

    q.page['scatter_viz_form_card'] = ui.form_card(
        box='1 5 4 4',
        items=[ui.visualization(
                plot=ui.plot(marks=plot_marks
                             ),
                data=data(
                    fields=df.columns.tolist(),
                    rows=df.values.tolist(),
                    pack=True
                ),
        )]
    )

Notice the pack=True of scatter_viz_form_card which is not required for scatter_plot_card. If you do not include it you get this error:

TypeError: Object of type Data is not JSON serializable

Actual Question

You can add pack=True to scatter_plot_card and nothing changes, but I am wondering why it's not required. Is this user confusion, a possible bug in ui.visualization, or missing docs?

@mtanco mtanco added docs Documentation ui Related to UI question Question labels Dec 22, 2020
@lo5
Copy link
Member

lo5 commented Jan 13, 2021

I can understand the confusion - this needs to be made clearer in the docs.

[1] is a card. Cards are backed by data buffers, which means they support incremental updates to individual rows or values in their data.

[2] is a component. It's not backed by data buffers, which means if you need to update a plot's data, you cannot use the simplified data-buffer syntax to edit individual values in the data. Instead, you'll need to do something like q.page['card_name'].items[0].visualization.data.rows[42][3] = 1024.

The pack=True indicates that you do not intend to edit individual rows or values in the data once the plot is rendered. Setting this attribute makes the server perform less work to host your page, and consequently improves performance.

We should probably make [2] work like [1] (without having to provide pack=True.

@lo5 lo5 added feature Feature request py Related to Python Driver and removed docs Documentation question Question ui Related to UI labels Jan 13, 2021
@lo5 lo5 changed the title h2o_wave.data works differently for ui.visualization and ui.plot_card Serialize Data automatically when referenced in components Jan 13, 2021
@lo5 lo5 changed the title Serialize Data automatically when referenced in components Avoid having to specify pack=True when using data() for components Mar 25, 2021
@mturoci mturoci self-assigned this Mar 24, 2023
mturoci added a commit that referenced this issue Jul 21, 2023
mturoci added a commit that referenced this issue Jul 21, 2023
mturoci added a commit that referenced this issue Jul 21, 2023
mturoci added a commit that referenced this issue Jul 31, 2023
mturoci added a commit that referenced this issue Jul 31, 2023
…tes are loaded due to Go arbitrary map iteration order. #441
mturoci added a commit that referenced this issue Jul 31, 2023
mturoci added a commit that referenced this issue Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request py Related to Python Driver
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants