Help displaying test app (from instructions) on a local web page

Hi,
Now that I seem to have Streamlit installed, I’m a bit confused as to how the various parts fit together (IDE, command line, local webpage) - specifically, what to do where to get an output on a local webpage.

I’m following the instructions on Main concepts - Streamlit Docs
I entered this code into my IDE (Thonny):

"""
# My first app
Here's our first attempt at using data to create a table:
"""

import streamlit as st
import pandas as pd
df = pd.DataFrame({
  'first column': [1, 2, 3, 4],
  'second column': [10, 20, 30, 40]
})

df

Then when I click ‘run’, shell returns the following:
2023-09-06 17:00:38.090
Warning: to view this Streamlit app on a browser, run it with the following
command:

streamlit run First Streamlit test.py [ARGUMENTS]

So first I added this line (streamlit run First Streamlit test.py ) to the bottom of my code and again clicked ‘run’ but that resulted in more errors (specifically, syntax errors).

Next, I added this code in the command line, that also resulted in errors:
Usage: streamlit run [OPTIONS] TARGET [ARGS]…
Try ‘streamlit run --help’ for help.

Error: Streamlit requires raw Python (.py) files, but the provided file has no extension.

So what do I do with the Python file I created (First Streamlit test.py ) to get it to display on the local webpage?

Separately (or maybe related?), in Thonny are many ‘extensions’, including Streamlit, should I also install it there? Would this help resolve the issue of displaying on a local webpage?

Thanks,
Mike

If your filename has spaces please enclose it in quotes

streamlit run "First Streamlit test.py"

ok, thanks for the reminder, I do recall in my Python courses you’ll always be safer with underscores than spaces.

Also, I figured out I was not saving the .py file in the correct place (it should have been in the environment I set up - doh!)
I copied it over and now when I enter the command in the teminal it immediately displays in the local webpage.

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