"Bad message format : i[o] is undefined" error with two containers

Hi @souravzzz,

Welcome to the Streamlit forum! :wave: :balloon:

I went digging through our GitHub issues to find similar issues:

Paraphrasing Ken鈥檚 comments on some issues: This is unintuitive behavior. A part of me thinks this is expected behavior (with a bad error message). Callbacks were designed to manipulate session state and not change the display of the app. Essentially, callbacks are called before the script runs, so while the variables c1 and c2 are defined, the containers do not currently exist (until the script run and is recreated again).

The solution is to not use callbacks for this use-case. Instead use a simple conditional to check if the button was clicked and, if so, call show_msg():

import streamlit as st

def show_msg():
    c2.write("You clicked Hello!")

st.title("Test Page")

# first container
c1 = st.container()

# second container
c2 = st.container()

if c1.button(label="Hello"):
    show_msg()

image

If you make the above change, you should no longer run into the error. If you feel none of the above linked issues adequately captures this issue, you鈥檙e welcome to submit a bug report in the Streamlit repo. Note: your bug report may be closed as a duplicate of one of the above issues.

1 Like