Chart.show() does not plot altair chart from .py script

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.

Take a look at the Streamlit documentation on charts.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.