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

Add support for selections to st.altair_chart & st.vega_lite_chart #8302

Merged
merged 354 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
354 commits
Select commit Hold shift + click to select a range
beb64fd
Fix JSON to string value
willhuang1997 Apr 15, 2024
5f814e2
Add new altair tests
willhuang1997 Apr 15, 2024
8d4931c
Add more vega lite unit tests for python
willhuang1997 Apr 15, 2024
37a21c0
Fix e2e tests
willhuang1997 Apr 15, 2024
b4b3ce4
Upgrade altair version
willhuang1997 Apr 15, 2024
ed65b35
Move stable id replacement to altair code
willhuang1997 Apr 16, 2024
27edf8b
Add check for altair version
willhuang1997 Apr 16, 2024
ba3bb08
Remove altair 5 requirement
willhuang1997 Apr 16, 2024
0a2254a
Fix data bug
willhuang1997 Apr 16, 2024
7eab15a
Fix altair tests
willhuang1997 Apr 16, 2024
8d3e8d9
Attempt to fix tests
willhuang1997 Apr 16, 2024
776973b
Attempt to move skip
willhuang1997 Apr 16, 2024
c461059
Readd watchdog
willhuang1997 Apr 16, 2024
dad5a51
fix bug that allowed selections to enter non-select plotly charts
willhuang1997 Apr 16, 2024
41b4260
Attempt to fix min-constraints
willhuang1997 Apr 16, 2024
4744ea0
remove boolean and change vegaliteSerde to vega_lite_serde
willhuang1997 Apr 17, 2024
187c737
Fix internal method
willhuang1997 Apr 17, 2024
cdcfb48
Fix comment
willhuang1997 Apr 17, 2024
510d0da
Migrate e2e tests with new on_select param
willhuang1997 Apr 17, 2024
95f0375
Add new github issue in message
willhuang1997 Apr 18, 2024
3e1b7bd
Add streamlit exception tests for altair 4
willhuang1997 Apr 18, 2024
018da37
Add streamlit exception tests for altair 4
willhuang1997 Apr 18, 2024
97a3cf3
Fix type errors
willhuang1997 Apr 18, 2024
0926d46
Minor fixes
willhuang1997 Apr 18, 2024
b0e60a3
Evaluate different mechanism to keep plotly state (#8515)
LukasMasuch Apr 19, 2024
b59fb6b
Attempt to remove bool for on select param (#8525)
willhuang1997 Apr 19, 2024
e19c5d6
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch Apr 19, 2024
4bfedbb
Merge branches 'feature/InteractiveCharts_Plotly' and 'feature/Intera…
LukasMasuch Apr 19, 2024
eb34b64
Add signature overloading
LukasMasuch Apr 19, 2024
a91f97a
Fix id generation for plotly and remove small comment
willhuang1997 Apr 19, 2024
8303ec2
Apply more refactorings and improvements
LukasMasuch Apr 19, 2024
21e7333
Merge branch 'feature/InteractiveCharts_Plotly' of https://github.com…
LukasMasuch Apr 19, 2024
6ab5fa3
Improve reset handling
LukasMasuch Apr 19, 2024
a3d252e
Add some more checks
LukasMasuch Apr 19, 2024
8017db6
Add more logs
LukasMasuch Apr 19, 2024
62c1469
Fix issue
LukasMasuch Apr 19, 2024
50ea41e
Change back to plotly mode
LukasMasuch Apr 19, 2024
c07c4ab
Change default to ignore
LukasMasuch Apr 19, 2024
99f361c
Correctly handle initial state
LukasMasuch Apr 19, 2024
e4ed5c1
Always respect available width as maximum
LukasMasuch Apr 19, 2024
e27ae39
Fix fragment support
LukasMasuch Apr 19, 2024
aadc196
Migrate fullscreen button to plotly toolbar
LukasMasuch Apr 19, 2024
e2f61a6
Further fixes
LukasMasuch Apr 20, 2024
4bd9db0
Don't update when selection mode is not activated
LukasMasuch Apr 20, 2024
772a562
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch Apr 20, 2024
788483a
Clean up safe types
LukasMasuch Apr 20, 2024
d97a1db
Minor refactorings
LukasMasuch Apr 20, 2024
3131a11
More refactorings
LukasMasuch Apr 20, 2024
960492c
Add more dependencies
LukasMasuch Apr 20, 2024
9d58e8e
Remove not needed code
LukasMasuch Apr 20, 2024
69158f0
Some refactoring into functions
LukasMasuch Apr 20, 2024
2845400
Deprecate the plotly sharing mode
LukasMasuch Apr 20, 2024
045f83e
Minor refactoring
LukasMasuch Apr 20, 2024
4eb6a83
Apply more improvements
LukasMasuch Apr 21, 2024
21ea00e
Remove unnecessary check
LukasMasuch Apr 21, 2024
74dc9b9
More refactoring
LukasMasuch Apr 22, 2024
802cf40
Remove some comments
LukasMasuch Apr 23, 2024
e80cbf4
Fix typechecking for Interactive Plotly Charts (#8550)
willhuang1997 Apr 23, 2024
59e521f
Refactor types
LukasMasuch Apr 23, 2024
cafc9fb
Remove unused interface
LukasMasuch Apr 23, 2024
5fb06f1
Remove more console logs
LukasMasuch Apr 23, 2024
ba9640e
Add tracing
LukasMasuch Apr 23, 2024
55dd677
Revert
LukasMasuch Apr 23, 2024
f0b6f17
Remove todo comment
LukasMasuch Apr 23, 2024
08e84fd
Remove console log
LukasMasuch Apr 23, 2024
674ed41
Small move
LukasMasuch Apr 23, 2024
2e2e67e
More cleanup
LukasMasuch Apr 23, 2024
8a016dd
Fix Python tests for Interactive Plotly Charts (#8551)
willhuang1997 Apr 23, 2024
0073042
Fix Playwright tests for Interactive Plotly Charts (#8552)
willhuang1997 Apr 23, 2024
326d1ff
Use Widget Callback
LukasMasuch Apr 23, 2024
eb8da4d
Remove default height
willhuang1997 Apr 23, 2024
2500722
Merge branch 'feature/InteractiveCharts_Plotly' of https://github.com…
willhuang1997 Apr 23, 2024
a01549c
Remove Callable from typing as it's unused
willhuang1997 Apr 23, 2024
d7efda0
Add new updated snapshots
willhuang1997 Apr 23, 2024
6ac7bef
Fix typing
willhuang1997 Apr 23, 2024
ff5c2d1
Remove junit tests because it's covered in e2e tests
willhuang1997 Apr 23, 2024
10b9f14
Add extra check for removing plotly config buttons
willhuang1997 Apr 23, 2024
67de052
Fix lint
willhuang1997 Apr 23, 2024
ff93577
Add snapshots
willhuang1997 Apr 23, 2024
fe14ecd
Fix failing snapshots
willhuang1997 Apr 23, 2024
2702bb0
Fix snapshots
willhuang1997 Apr 23, 2024
57352f4
Add Interactive Plotly typescript unit tests (#8557)
willhuang1997 Apr 24, 2024
7f2df77
Fix double click Plotly behavior (#8561)
willhuang1997 Apr 24, 2024
6a94479
Fix comment and remove some other comments
willhuang1997 Apr 24, 2024
2f8aab3
Merge branch 'feature/InteractiveCharts_Plotly' into feature/Interact…
willhuang1997 Apr 24, 2024
2453531
Fix merge conflict
willhuang1997 Apr 24, 2024
d23b962
Fix import and add docstring for replace_dict method
willhuang1997 Apr 24, 2024
c4fc38d
Refactor because chart_util got removed
willhuang1997 Apr 24, 2024
fd80141
Refactor AttributeDictionary to VegaLiteState and fix improts
willhuang1997 Apr 24, 2024
daf575f
Move skip in unit test
willhuang1997 Apr 24, 2024
baed1d0
refactors
willhuang1997 Apr 25, 2024
b505e38
Remove useCallback beacuse it's class component...
willhuang1997 Apr 25, 2024
66983ce
Fix point selection being enabled when it shouldnt be
willhuang1997 Apr 26, 2024
aa2f176
Add tests for selection_mode and fix bug where single selection mode …
sfc-gh-wihuang Apr 26, 2024
0ac433e
Revert "Fix point selection being enabled when it shouldnt be"
willhuang1997 Apr 27, 2024
4ac4548
Add unit test for widget replay
LukasMasuch Apr 27, 2024
b985442
More unit tests
LukasMasuch Apr 27, 2024
c539481
Add another test
LukasMasuch Apr 27, 2024
f8c408b
Improve test
LukasMasuch Apr 27, 2024
9841246
Merge branch 'feature/InteractiveCharts_Plotly' into feature/Interact…
willhuang1997 Apr 27, 2024
54a8323
Deactivate point selection if selection mode doesn't include points (…
LukasMasuch Apr 27, 2024
06d6c5d
Remove unnecessary buttons in Plotly toolbar (#8571)
sfc-gh-wihuang Apr 27, 2024
6b41328
Only activate selection types if selections are activated
LukasMasuch Apr 27, 2024
efaacc8
Use next line eslint ignores for dependencies
LukasMasuch Apr 27, 2024
fc4b23f
Fix selection mode parsing
LukasMasuch Apr 27, 2024
4ef76c8
Improve selection mode parsing test
LukasMasuch Apr 27, 2024
ba962fa
Recreate snapshots
LukasMasuch Apr 27, 2024
cf3e62d
Fix plotly tab change flickering (#8577)
LukasMasuch Apr 27, 2024
06244c7
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch Apr 27, 2024
7fb856a
Add updated snapshots
LukasMasuch Apr 27, 2024
9933844
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch Apr 27, 2024
ac84eb2
Some cleanups
LukasMasuch Apr 27, 2024
7031468
Merge branch 'develop' into feature/InteractiveCharts_Plotly
willhuang1997 Apr 28, 2024
51db920
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch Apr 29, 2024
05304ae
Fix Interactive Plotly e2e playwright nits (#8579)
willhuang1997 Apr 29, 2024
56c6407
Mini changes
LukasMasuch Apr 29, 2024
bd74635
Minor fine-tuning
LukasMasuch Apr 29, 2024
03f7e5e
More improvements
LukasMasuch Apr 29, 2024
6c4817c
Some more tweaks
LukasMasuch Apr 29, 2024
a423efe
More tweaks
LukasMasuch Apr 29, 2024
071204a
Remove test
LukasMasuch Apr 29, 2024
f1ba990
More fine-tuning
LukasMasuch Apr 29, 2024
2995b74
Click somewhere else
LukasMasuch Apr 29, 2024
3b0a738
More fine-tuning
LukasMasuch Apr 29, 2024
d5454ae
Update snapshots
LukasMasuch Apr 29, 2024
d4d0b0a
Add test with box & points
LukasMasuch Apr 29, 2024
0e88d7b
More changes
LukasMasuch Apr 29, 2024
00c50e1
Just check point count and not dataframe visuals
LukasMasuch Apr 29, 2024
4e4421d
Minor proto restructuring
LukasMasuch Apr 29, 2024
50caac6
Remove flakiness
LukasMasuch Apr 29, 2024
c61d197
Update snapshots
LukasMasuch Apr 29, 2024
2eb72f7
Merge branch 'develop' into feature/InteractiveCharts_Plotly
LukasMasuch Apr 29, 2024
69b95ef
Add unit test for box and lasso selection (#8585)
willhuang1997 Apr 29, 2024
2a55a67
Remove follow redirects in yarn lock
willhuang1997 Apr 29, 2024
ce3aa20
Add hover before snapshots
LukasMasuch Apr 29, 2024
7b9a522
Add new snapshots
willhuang1997 Apr 29, 2024
e5bb687
Add new snapshots
willhuang1997 Apr 29, 2024
7374c92
Add new updated snapshots
willhuang1997 Apr 29, 2024
9b0a727
Add test for deprecation warning
LukasMasuch Apr 29, 2024
f738771
Improve docstring
LukasMasuch Apr 29, 2024
27cf334
Remove extra quotations"
willhuang1997 Apr 29, 2024
276ed8f
add final new snapshot
willhuang1997 Apr 29, 2024
bb770bf
Remove choropleth chart
LukasMasuch Apr 29, 2024
efa0b79
Remove unused dependencies
LukasMasuch Apr 29, 2024
dda8ba6
Update snapshots
LukasMasuch Apr 29, 2024
cd2e96d
Improve test
LukasMasuch Apr 29, 2024
15df246
Fix test
willhuang1997 Apr 29, 2024
8fefff5
Fix test
willhuang1997 Apr 29, 2024
a142b3d
Merge branch 'feature/InteractiveCharts_Plotly' into feature/Interact…
willhuang1997 Apr 29, 2024
7d32594
Use direct chart click
LukasMasuch Apr 29, 2024
1def33f
Add new screenshots(?)
willhuang1997 Apr 29, 2024
c7609f2
Merge branch 'feature/InteractiveCharts_Plotly' into feature/Interact…
willhuang1997 Apr 29, 2024
ed37b7f
Fix imports
willhuang1997 Apr 29, 2024
5d66f3c
Merge branch 'develop' into feature/InteractiveCharts_Altair
willhuang1997 Apr 29, 2024
4e3a9fc
[InteractiveChartsAltair] Form support for Interactive charts altair …
willhuang1997 Apr 30, 2024
156e9ac
Fix nits and codeql
willhuang1997 Apr 30, 2024
563fd4d
Refactor constants
willhuang1997 Apr 30, 2024
ba8dbab
Merge branch 'develop' into feature/InteractiveCharts_Altair
willhuang1997 Apr 30, 2024
44943a1
Add new e2e test and fix some if else statement
willhuang1997 Apr 30, 2024
081b5d3
Merge branch 'feature/InteractiveCharts_Altair' of https://github.com…
willhuang1997 Apr 30, 2024
e48923d
Add snapshots
willhuang1997 Apr 30, 2024
06c1e47
Fix some comments and vega lite form bug
willhuang1997 Apr 30, 2024
84b7433
Remove unnecessary code
willhuang1997 Apr 30, 2024
c5abc9e
Add cache replay test and cache replay check with some refactors
willhuang1997 May 1, 2024
da143df
Remove unnecessary import
willhuang1997 May 1, 2024
0b0361b
Add cache replay and move imports
willhuang1997 May 1, 2024
6a93f7a
Attempt to move import
willhuang1997 May 1, 2024
0841ded
Fix nit
willhuang1997 May 1, 2024
736d946
Move imports
willhuang1997 May 1, 2024
eb65c26
Merge branch 'develop' into feature/InteractiveCharts_Altair
willhuang1997 May 1, 2024
a45ad4c
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 2, 2024
cb71d6b
Some small refactorings
LukasMasuch May 2, 2024
c19bfa1
Move to widgets
LukasMasuch May 3, 2024
b883d09
Sort widgets list
LukasMasuch May 3, 2024
cd4f816
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 3, 2024
5d3ca7e
Refactor selections logic
LukasMasuch May 3, 2024
2cb52de
Add better comments
LukasMasuch May 3, 2024
8e1f48c
Clean up yarn lock file
LukasMasuch May 3, 2024
dae3de3
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 6, 2024
e9b9a47
Add properties
LukasMasuch May 6, 2024
6d600b9
Add some solutions for stabilizing the vega lite spec
LukasMasuch May 7, 2024
83ed8b3
Use different logic to stabilize the spec
LukasMasuch May 7, 2024
0d1e316
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 8, 2024
5b945e3
Remove generated code
LukasMasuch May 8, 2024
a8bf2e7
Remove duplicated function
LukasMasuch May 8, 2024
35380ab
Move import
LukasMasuch May 8, 2024
96986df
Improve comments
LukasMasuch May 8, 2024
0f267b7
Add additional test
LukasMasuch May 8, 2024
81af60c
Fix unit test
LukasMasuch May 8, 2024
828b8b6
Fix types
LukasMasuch May 8, 2024
f2ee02c
Add comment
LukasMasuch May 8, 2024
d655915
Move something
LukasMasuch May 8, 2024
4d654f2
Update proto comments
LukasMasuch May 8, 2024
4ca05b0
Correctly cast to delta generator
LukasMasuch May 8, 2024
2c4d1c9
Fix unit tests
LukasMasuch May 8, 2024
5d9d7a8
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 9, 2024
c0858ce
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 10, 2024
d6a189f
Add type alias for vega spec
LukasMasuch May 10, 2024
ff5714d
Frontend refactoring and cleanup
LukasMasuch May 10, 2024
9e7d5a3
Update st_altair_chart_basic_select
raethlein May 10, 2024
6ed8ed5
Update e2e tests
raethlein May 10, 2024
0667b62
Disallow composite charts
LukasMasuch May 12, 2024
4c21857
Add vega datasets to test-dependencies
LukasMasuch May 12, 2024
85a09bf
Add more comments
LukasMasuch May 12, 2024
928a3f0
Snapshot with commented out code
LukasMasuch May 12, 2024
3f3dde9
Some more refactoring
LukasMasuch May 12, 2024
1528976
Clean up logs
LukasMasuch May 12, 2024
0d4a3df
Introduce selection modes
LukasMasuch May 12, 2024
7c364b2
Fix issue
LukasMasuch May 12, 2024
05382c1
Delete concatenated chart e2e tests
LukasMasuch May 12, 2024
b28724a
Use selection mode from element
LukasMasuch May 12, 2024
efbfb7d
Remove utils method
LukasMasuch May 12, 2024
b0b0171
Remove the state variable
LukasMasuch May 12, 2024
15a2a39
Clean up console logs
LukasMasuch May 13, 2024
6927999
Use more local datasets
LukasMasuch May 13, 2024
58a39de
Initialize selection params with empty dicts
LukasMasuch May 13, 2024
543509d
Add more comments
LukasMasuch May 13, 2024
28fea60
Simplify code
LukasMasuch May 13, 2024
5a1ab9c
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 13, 2024
7c6474b
Update e2e tests
raethlein May 13, 2024
bf70184
Some small refinements
LukasMasuch May 13, 2024
5971324
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 13, 2024
e0cacf1
Rename widget name to vega_lite_chart
LukasMasuch May 13, 2024
3e9685d
Fix bare execution of chart-selection test app
raethlein May 13, 2024
7ed071a
Fix typing issue
LukasMasuch May 13, 2024
11457bf
Merge branch 'feature/InteractiveCharts_Altair' of https://github.com…
LukasMasuch May 13, 2024
2b925da
Fix unit tests
LukasMasuch May 13, 2024
6b45d68
Add future annotations
LukasMasuch May 13, 2024
03ee086
Fix test
LukasMasuch May 13, 2024
4ea99fb
Fix typing issues
LukasMasuch May 13, 2024
21757fa
Add more tests
LukasMasuch May 13, 2024
ce891f9
Improve unit tests
LukasMasuch May 13, 2024
08a0729
Remove print
LukasMasuch May 13, 2024
0385266
Fix test
LukasMasuch May 13, 2024
e82ea5e
Update tests
raethlein May 14, 2024
aa982ae
Apply review comments
LukasMasuch May 14, 2024
6b2d820
Update comment
LukasMasuch May 14, 2024
83ea606
Simplify removal
LukasMasuch May 14, 2024
5808e4d
Merge remote-tracking branch 'upstream/develop' into feature/Interact…
LukasMasuch May 14, 2024
c66a2ca
Update comment
LukasMasuch May 14, 2024
e2a686e
Use regex in e2e tests
raethlein May 14, 2024
00ba60b
Update e2e test regexes
raethlein May 14, 2024
81f126c
Update e2e test regexes
raethlein May 14, 2024
75b27c3
Update e2e test regexes
raethlein May 14, 2024
724c9ad
Update snapshots
raethlein May 14, 2024
82f0193
Merge remote-tracking branch 'origin/develop' into feature/Interactiv…
raethlein May 14, 2024
4513655
Skip firefox in unmount test
raethlein May 14, 2024
e02eee5
Update snapshots
LukasMasuch May 14, 2024
7632c88
Revert locator changes in e2e test
raethlein May 14, 2024
13146b2
Update snapshots
raethlein May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
226 changes: 226 additions & 0 deletions e2e_playwright/st_altair_chart_basic_select.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import time

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

import streamlit as st

# SCATTER CHART
st.header("Altair Chart with point and interval selection")

# taken from vega_datasets cars example
cars = data.cars()
interval = alt.selection_interval()

point = alt.selection_point()

st.subheader("Scatter chart with selection_point")

if st.button("Create some elements to unmount component"):
for _ in range(3):
# The sleep here is needed, because it won't unmount the
# component if this is too fast.
time.sleep(1)
st.write("Another element")

base = (
alt.Chart(cars)
.mark_point()
.encode(
x="Horsepower:Q",
y="Miles_per_Gallon:Q",
color=alt.condition(point, "Origin:N", alt.value("lightgray")),
tooltip=alt.value(None),
)
)
chart_point = base.add_params(point)
st.altair_chart(
chart_point, on_select="rerun", key="scatter_point", use_container_width=True
)
if (
"scatter_point" in st.session_state
and len(st.session_state.scatter_point.select) > 0
):
st.write("Scatter chart with selection_point:", str(st.session_state.scatter_point))

st.subheader("Scatter chart with selection_interval")
base = (
alt.Chart(cars)
.mark_point()
.encode(
x="Horsepower:Q",
y="Miles_per_Gallon:Q",
color=alt.condition(interval, "Origin:N", alt.value("lightgray")),
tooltip=alt.value(None),
)
)
chart_interval = base.add_params(interval)
# Set use_container_width=True for all charts so that the width is not dependent on Vega-lib updates.
st.altair_chart(
chart_interval, on_select="rerun", key="scatter_interval", use_container_width=True
)
if (
"scatter_interval" in st.session_state
and len(st.session_state.scatter_interval.select) > 0
):
st.write(
"Scatter chart with selection_interval:", str(st.session_state.scatter_interval)
)

# BAR CHART
st.subheader("Bar chart with selection_point")
source = pd.DataFrame(
{
"a": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
"b": [28, 55, 43, 91, 81, 53, 19, 87, 52],
}
)

bar_graph_point = (
alt.Chart(source)
.mark_bar()
.encode(
x="a",
y="b",
fillOpacity=alt.condition(point, alt.value(1), alt.value(0.3)),
tooltip=alt.value(None),
)
.add_params(point)
)
st.altair_chart(
bar_graph_point, on_select="rerun", key="bar_point", use_container_width=True
)
if "bar_point" in st.session_state and len(st.session_state.bar_point.select) > 0:
st.write("Bar chart with selection_point:", str(st.session_state.bar_point))


bar_graph_interval = (
alt.Chart(source)
.mark_bar()
.encode(
x="a",
y="b",
fillOpacity=alt.condition(interval, alt.value(1), alt.value(0.3)),
tooltip=alt.value(None),
)
.add_params(interval)
)

st.subheader("Bar chart with selection_interval")
st.altair_chart(
bar_graph_interval, on_select="rerun", key="bar_interval", use_container_width=True
)
if "bar_interval" in st.session_state and len(st.session_state.bar_interval.select) > 0:
st.write("Bar chart with selection_interval:", str(st.session_state.bar_interval))

# STACKED AREA CHART
source = data.iowa_electricity()

base = (
alt.Chart(source)
.mark_area()
.encode(
x="year:T",
y="net_generation:Q",
color=alt.condition(point, "source:N", alt.value("lightgray")),
tooltip=alt.value(None),
)
)
area_chart_point = base.add_params(point)
st.subheader("Area chart with selection_point")
selection = st.altair_chart(
area_chart_point, on_select="rerun", key="area_point", use_container_width=True
)
if len(selection.select) > 0:
st.write("Area chart with selection_point:", str(selection.select))


base = (
alt.Chart(source)
.mark_area()
.encode(
x="year:T",
y="net_generation:Q",
color=alt.condition(interval, "source:N", alt.value("lightgray")),
tooltip=alt.value(None),
)
)
area_chart_interval = base.add_params(interval)
st.subheader("Area chart with selection_interval")
area_interval_selection = st.altair_chart(
area_chart_interval,
on_select="rerun",
key="area_interval",
use_container_width=True,
)
if len(area_interval_selection.select) > 0:
st.write("Area chart with selection_interval:", str(area_interval_selection.select))

# HISTOGRAM CHART
source = data.movies()

base = (
alt.Chart(source)
.mark_bar()
.encode(
alt.X("IMDB_Rating:Q", bin=True),
y="count()",
color=alt.condition(point, "IMDB_Rating:Q", alt.value("lightgray")),
tooltip=alt.value(None),
)
)
histogram_point = base.add_params(point)
st.subheader("Histogram chart with selection_point")
st.altair_chart(
histogram_point, on_select="rerun", key="histogram_point", use_container_width=True
)
if (
"histogram_point" in st.session_state
and len(st.session_state.histogram_point.select) > 0
):
st.write(
"Histogram chart with selection_point:", str(st.session_state.histogram_point)
)

base = (
alt.Chart(source)
.mark_bar()
.encode(
alt.X("IMDB_Rating:Q", bin=True),
y="count()",
color=alt.condition(interval, "IMDB_Rating:Q", alt.value("lightgray")),
tooltip=alt.value(None),
)
)
histogram_interval = base.add_params(interval)
st.subheader("Histogram chart with selection_interval")
st.altair_chart(
histogram_interval,
on_select="rerun",
key="histogram_interval",
use_container_width=True,
)
if (
"histogram_interval" in st.session_state
and len(st.session_state.histogram_interval.select) > 0
):
st.write(
"Histogram chart with selection_interval:",
str(st.session_state.histogram_interval),
)