Direct the output of to web page

How to direct the output of to web page. Currently the ouput of st.write( and st.text( both are being redirected to prompt console.

Hi @cyruslentin, welcome to the Streamlit community!! :wave: :partying_face:

The pandas documentation for says, by default, the output is printed to sys.stdout. This behavior is governed by the buf parameter which defaults to sys.stdout.

To display the output in your Streamlit app, pipe the output of to a buffer instead of sys.stdout, get the buffer content, and display it with st.text like so:

import streamlit as st
import pandas as pd
import io

df = pd.DataFrame(
        "foo": ["hello", "world", "foo " * 30],
        "bar": ["hello", "world", "bar" * 30],
        "baz": [1, 2, 3],

buffer = io.StringIO()
s = buffer.getvalue()



Happy Streamlit’ing! :balloon:


@snehankekre - thank you for the lucid explanation along with the solution. The solution you provided worked. Thanks again

1 Like