Search code examples
pythonpandasdataframestreamlit

How to display excel file in streamlit?


I'm trying to display the complete excel data in streamlit but why does it look different from the original?

the right side is the original excel file and on the left side is the excel file that is in streamlit

from streamlit_option_menu import option_menu
import pandas as pd

# 1. as sidebar menu
with st.sidebar:
    selected = option_menu("Product", ["BFR CORPORATE", 'BFR mikro', 'BFR Consumer', 'BRF'], 
        icons=['play', 'play'], menu_icon="cast", default_index=1)
    selected
    print(selected)
df = pd.read_excel("contoh.xlsx")
st.dataframe(df)

Solution

  • Use Streamlit AgGrid Component which is installed as pip install streamlit-aggrid to display your dataframe. That might handle the problem you are facing.

    With regards to the colour, I am pretty sure will have to write some CSS to acomplish that.

    Import the module as from st_aggrid import AgGrid, after installing it.

    from st_aggrid import AgGrid
    
    AgGrid(df)
    

    You might want to go through the AgGrid Doc for more information because it comes with a bunch of features which you might be interested, with regards to the styling of dataframes.

    I will recommend you to visit streamlit-aggrid component to have a glance on how the module is implemented in streamlit.