Streamlit Columns TypeError: 'DeltaGenerator' object is not callable

I am trying to use st.columns, but it is giving me a DeltaGenerator TypeError when using with col1(). What am I doing wrong?

Code Snippet

import streamlit as st
...
# Create columns
col1, col2 = st.columns(2)

# Now plot the graphs
with col1():
    st.markdown('#### Job Growth')
    st.line_chart(
            msas_to_plot_jobs,
            x='date'
            )

with col2():
    st.markdown('#### M-o-M Percent Change')

Error Message

TypeError: ‘DeltaGenerator’ object is not callable

Traceback:

File "/Users/WonderWolff/Real_Estate/projects_to_publish/msa_rank_dashboard/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)File "/Users/WonderWolff/Real_Estate/projects_to_publish/msa_rank_dashboard/streamlit_app.py", line 179, in <module>
    with col1():

Debug Info
Local deployment.
Streamlit version: 1.34.0
Python version: 3.9.3
OS version: Mac 12.7.5

Indeed you cannot do that. Look at the examples in the docs.

Thank you! You’re right, the docs don’t call col1, whereas I did with col1(). For my future reference, here’s the code snippet directly from the docs: st.columns - Streamlit Docs

import streamlit as st

col1, col2, col3 = st.columns(3)

with col1:
   st.header("A cat")
   st.image("https://static.streamlit.io/examples/cat.jpg")

with col2:
   st.header("A dog")
   st.image("https://static.streamlit.io/examples/dog.jpg")

with col3:
   st.header("An owl")
   st.image("https://static.streamlit.io/examples/owl.jpg")

This is solved.

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