Repository: streamlit/streamlit
File: lib/streamlit/elements/layouts.py (Python)

Code before:
            height: 750px

        Or you can just call methods directly on the returned objects:

        >>> import streamlit as st
        >>>
        >>> st.bar_chart({"data": [1, 5, 2, 6, 2, 1]})
        >>>
        >>> expander = st.expander("See explanation")
        >>> expander.write('''
        ...     The chart above shows some numbers I picked for you.
        ...     I rolled actual dice for these, so they're *guaranteed* to
        ...     be random.
        ... ''')
        >>> expander.image("https://static.streamlit.io/examples/dice.jpg")

        .. output::
            https://doc-expander.streamlit.app/
            height: 750px

        """
        if label is None:
            raise StreamlitAPIException("A label is required for an expander")

        if not callable(on_change) and on_change not in {"ignore", "rerun"}:
            raise StreamlitValueError("on_change", ["'rerun'", "'ignore'"])

        if not callable(on_change) and (args is not None or kwargs is not None):
            raise StreamlitAPIException(
                "`args` and `kwargs` can only be used when `on_change` is a callable."
            )

        key = to_key(key)
        is_stateful = on_change != "ignore"

        current_expanded = expanded
        element_id: str | None = None

        if is_stateful:
            check_widget_policies(
                self.dg,
                key,
                on_change=on_change if callable(on_change) else None,
                default_value=None,
                writes_allowed=True,
                enable_check_callback_rules=callable(on_change),
            )

            ctx = get_script_run_ctx()

            element_id = compute_and_register_element_id(

Review comment (suggestion):
**suggestion:** Consider adding `"a callable"` to the StreamlitValueError.

Code after:
            height: 750px

        Or you can just call methods directly on the returned objects:

        >>> import streamlit as st
        >>>
        >>> st.bar_chart({"data": [1, 5, 2, 6, 2, 1]})
        >>>
        >>> expander = st.expander("See explanation")
        >>> expander.write('''
        ...     The chart above shows some numbers I picked for you.
        ...     I rolled actual dice for these, so they're *guaranteed* to
        ...     be random.
        ... ''')
        >>> expander.image("https://static.streamlit.io/examples/dice.jpg")

        .. output::
            https://doc-expander.streamlit.app/
            height: 750px

        """
        if label is None:
            raise StreamlitAPIException("A label is required for an expander")

        if not callable(on_change) and on_change not in {"ignore", "rerun"}:
            raise StreamlitValueError(
                "on_change", ["'rerun'", "'ignore'", "a callable"]
            )

        if not callable(on_change) and (args is not None or kwargs is not None):
            raise StreamlitAPIException(
                "`args` and `kwargs` can only be used when `on_change` is a callable."
            )

        key = to_key(key)
        is_stateful = on_change != "ignore"

        current_expanded = expanded
        element_id: str | None = None

        if is_stateful:
            check_widget_policies(
                self.dg,
                key,
                on_change=on_change if callable(on_change) else None,
                default_value=None,
                writes_allowed=True,
                enable_check_callback_rules=callable(on_change),
            )

            ctx = get_script_run_ctx()