Summary
I have code in a .py script. Code for an altair chart. I want to plot it. I get an error instead
Steps to reproduce
Code snippet:
import pandas as pd
import numpy as np
import streamlit as st
import altair as alt
alt.renderers.enable('altair_viewer')
from datetime import time, datetime
from vega_datasets import data as vega_data
movies_df = pd.read_json(vega_data.movies.url)
def extract_year(value):
return pd.to_datetime(value, format="%b %d %Y").year
movies_df['year'] = movies_df.Release_Date.apply(extract_year)
print(movies_df['year'].value_counts())
movies_2000 = movies_df.loc[movies_df.year == 2000]
print(movies_2000.shape)
chart = alt.Chart(movies_2000).mark_point().encode(
x='Production_Budget',
y='Worldwide_Gross',
size='US_Gross',
color='Rotten_Tomatoes_Rating',
tooltip=['Title', 'Production_Budget', 'Worldwide_Gross']
).interactive()
chart.show()
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
Plotting the chart.
Actual behavior:
Traceback (most recent call last):
File “C:\Users\Hans\anaconda3\envs\streamlit-env\lib\site-packages\IPython\core\interactiveshell.py”, line 3508, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 27, in
chart.show()
File “C:\Users\Hans\anaconda3\envs\streamlit-env\lib\site-packages\altair\vegalite\v5\api.py”, line 2280, in show
altair_viewer.show(self, embed_opt=embed_opt, open_browser=open_browser)
File “C:\Users\Hans\anaconda3\envs\streamlit-env\lib\site-packages\altair_viewer_viewer.py”, line 355, in show
msg = self.display(chart, embed_opt=embed_opt, open_browser=open_browser)
File “C:\Users\Hans\anaconda3\envs\streamlit-env\lib\site-packages\altair_viewer_viewer.py”, line 268, in display
raise RuntimeError(“Internal: _stream is not defined.”)
RuntimeError: Internal: _stream is not defined.
Debug info
- Streamlit version:1.23.1
- Python version: .10
- Using Conda
- OS version: WIndows
- Browser version: Chrome
Requirements file
Links
- Link to your GitHub repo:
- Link to your deployed app:
Additional information
If needed, add any other context about the problem here.