Magic
Magic commands are a feature in Streamlit that allows you to write almost anything (markdown, data, charts) without having to type an explicit command at all. Just put the thing you want to show on its own line of code, and it will appear in your app. Here's an example:
How Magic works
Any time Streamlit sees either a variable or literal
value on its own line, it automatically writes that to your app using
st.write (which you'll learn about later).
Also, magic is smart enough to ignore docstrings. That is, it ignores the strings at the top of files and functions.
If you prefer to call Streamlit commands more explicitly, you can always turn
magic off in your ~/.streamlit/config.toml with the following setting:
Important
Right now, Magic only works in the main Python app file, not in imported files. See GitHub issue #288 for a discussion of the issues.
Featured video
Learn what the st.write and magic commands are and how to use them.
Still have questions?
Our forums are full of helpful information and Streamlit experts.
