Closed ztawilvdl closed 23 minutes ago
Thanks for sharing this repro. This is definitely a bug. marimo tries to add its own selection (automatically), so I think we need to handle the case when you've added your own selection.
Would you expect marimo to not add any selection or augment (if it can) with the selection params you have added? My guess it the former: if any selection is present, we don't add this for you.
@mscolnick I don't think I quite follow (I'm pretty new to Altair so pardon the ignorance). Why is the selection
piece the issue when the chart is layered? I don't quite understand why that would affect the selection since everything works if it's not a layered chart.
Edit:
And when doing a concat
vs layer
it works
This will work
_base = alt.Chart(long_counts)
_brush = alt.selection_interval(encodings=['x'])
_point = alt.selection_point(encodings=['x'])
_chart = (
_base.mark_bar().encode(
x=alt.X('Level1').sort(order="descending").title("Subpillar"),
y=alt.Y('count').title("Number of Companies"),
color=alt.condition(_point, "stage", alt.value('lightgray')),
tooltip=alt.Tooltip(["Level1", "count", "stage"])
)
.add_params(_point, _brush)
)
_rule = _base.mark_point(strokeDash=[2, 2]).encode(
x=alt.X('Level1').sort(order="descending").title("Subpillar"),
y=alt.Y('count').title("Number of Companies"),
color=alt.datum("Early Venture")
).add_params(_point, _brush)
mo_chart = mo.ui.altair_chart((_chart | _rule))
# mo_chart = mo.ui.altair_chart((_chart))
mo_chart
mo.ui.altair_chart
effectively adds selection as well, there is a chart_selection
and field_selection
param that you could try to toggle. I don't know the exact issue, but I imagine that our automatically added selection doesn't play nicely with your explicit selection.
Ooooh. I didn't realize that it added it. Weird that it works when it's not layered. When I remove the selection and let Marimo handle it, I see weird behaviour with the values updating
Freshly executed cell with the charts ✅
Click middle bar, values update ✅
Click right bar, values don't update ❌
Going back to your question:
Would you expect marimo to not add any selection or augment (if it can) with the selection params you have added? My guess it the former: if any selection is present, we don't add this for you.
I don't know. I guess I don't like magic, so if I have a selection maybe you don't do any because I might not want it.
Yea, I think we likely just don't handle layers well at all. Given your examples, I can take a look and make sure we handle them properly (or warn why we cannot)
Sweet, this works I think:
test_counts = pd.DataFrame([
{"Level1": "a", "count": 1, "stage": "france"},
{"Level1": "b", "count": 2, "stage": "france"},
{"Level1": "c", "count": 3, "stage": "england"}
])
_base = alt.Chart(test_counts)
_point = alt.selection_point(encodings=['x'])
_brush = alt.selection_interval(encodings=['x'])
_chart = (
_base.mark_bar().encode(
x=alt.X('Level1').sort(order="descending").title("Subpillar"),
y=alt.Y('count').title("Number of Companies"),
color=alt.condition(_point, "stage", alt.value('lightgray')),
)
.add_params(_point, _brush)
)
_rule = _base.mark_rule(strokeDash=[2, 2]).encode(
y=alt.datum(2),
color=alt.datum("england")
)
# This will cause error
mo_chart1 = mo.ui.altair_chart(
(alt.layer(_chart, _rule)),
chart_selection=None,
)
mo_chart1
# alt.layer(_chart, _rule)
Describe the bug
When trying to create an
mo.ui.altair_chart
using a layered Altair chart that has aselection_point
attached, we get an error of:However, when removing one of the layers it works. Or when removing the
selection_point
from the chart creation it works.Environment
Code to reproduce
This will cause the error
This works
This also works