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

Support Altair 5 #4486

Closed
joelostblom opened this issue Mar 2, 2023 · 3 comments · Fixed by #4488
Closed

Support Altair 5 #4486

joelostblom opened this issue Mar 2, 2023 · 3 comments · Fixed by #4488
Labels
type: bug Something isn't correct or isn't working

Comments

@joelostblom
Copy link
Contributor

Is your feature request related to a problem? Please describe.

The first rc for altair 5 was just released, and the panel demos are now failing with AttributeError: 'Selection.param' object has no attribute 'brush' (with panel 0.14.3).

import pandas as pd
import altair as alt
import panel as pn

pn.extension('vega')

penguins_url = "https://raw.githubusercontent.com/vega/vega/master/docs/data/penguins.json"
df = pd.read_json(penguins_url)

brush = alt.selection_interval(name='brush')  # selection of type "interval"

chart = alt.Chart(penguins_url).mark_point().encode(
    x=alt.X('Beak Length (mm):Q', scale=alt.Scale(zero=False)),
    y=alt.Y('Beak Depth (mm):Q', scale=alt.Scale(zero=False)),
    color=alt.condition(brush, 'Species:N', alt.value('lightgray'))
).properties(
    width=250,
    height=250
).add_selection(
    brush
)

vega_pane = pn.pane.Vega(chart, debounce=10)

def filtered_table(selection):
    if not selection:
        return '## No selection'
    query = ' & '.join(
        f'{crange[0]:.3f} <= `{col}` <= {crange[1]:.3f}'
        for col, crange in selection.items()
    )
    return pn.Column(
        f'Query: {query}',
        pn.pane.DataFrame(df.query(query), width=600, height=300)
    )

pn.Row(vega_pane, pn.bind(filtered_table, vega_pane.selection.param.brush))
AttributeError: 'Selection.param' object has no attribute 'brush'

Same as #4477 but more context.

@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Mar 2, 2023
@philippjfr philippjfr modified the milestones: v1.0.0, next, Version 0.14.4 Mar 2, 2023
@joelostblom
Copy link
Contributor Author

Awesome, thanks for the speedy fix!

@sriramvenkateshan
Copy link

Guys, this still does not work - it runs without exceptions/errors but does not give the valid selection object
Using the v0.14.4, (and also in the demo on the example page), I see "no selection" all the time instead of the updated table

@joelostblom
Copy link
Contributor Author

@sriramvenkateshan The interactive examples will not work on the webpage, you have to download the documentation notebooks or copy the code. Here is an example from the docs that works for me locally (make sure to restart jupyterlab if you have it open since previously, and double check that you are are on the right version of the libraries):

import altair as alt
import pandas as pd
import panel as pn
from vega_datasets import data

pn.extension('vega')

penguins_url = "https://raw.githubusercontent.com/vega/vega/master/docs/data/penguins.json"

df = pd.read_json(penguins_url)

brush = alt.selection_interval(name='brush')  # selection of type "interval"

chart = alt.Chart(penguins_url).mark_point().encode(
    x=alt.X('Beak Length (mm):Q', scale=alt.Scale(zero=False)),
    y=alt.Y('Beak Depth (mm):Q', scale=alt.Scale(zero=False)),
    color=alt.condition(brush, 'Species:N', alt.value('lightgray'))
).properties(
    width=250,
    height=250
).add_params(
    brush
)

vega_pane = pn.pane.Vega(chart, debounce=10)

def filtered_table(selection):
    if not selection:
        return '## No selection'
    query = ' & '.join(
        f'{crange[0]:.3f} <= `{col}` <= {crange[1]:.3f}'
        for col, crange in selection.items()
    )
    return pn.Column(
        f'Query: {query}',
        pn.pane.DataFrame(df.query(query), width=600, height=300)
    )

pn.Row(vega_pane, pn.bind(filtered_table, vega_pane.selection.param.brush))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants