Experimental data editor style

st.experimental_data_editor seems to not accept data frame styler, only st.dataframe

I would like to center my elements with st.experimental_data_editor, how could I do that?

Hi @Davi_Augusto_Bandeir
Did you try using st.data_editor instead ?

I tried and I get the following error:
AttributeError: module ‘streamlit’ has no attribute ‘data_editor’

st.data_editor is present since last version (1.23.0) of streamlit. Update your requirements and try again :wink:

I just did that, but the style function is still not working

import streamlit as st
import pandas as pd

th_props = [('font-size', '16px'), ('text-align', 'center'), ('font-weight', 'bold'), ('color', '#FFFFFF'), ('background-color', '#222B35')]
td_props = [('font-size', '14px'), ('text-align', 'center')]

styles = [dict(selector="th", props=th_props), dict(selector="td", props=td_props)]

df = pd.DataFrame({'A': [1, 2], 'B': [2, 2]})

I just found this thread which explain pandas styler is not currently supported.
Maybe a moderator has any news about this ?

1.23 added limited pandas styler support to st.data_editor, but only for non-editable/disabled columns. I don’t think this will help in your case. We have considered adding alignment as part of the column config API, but decided against that for the first release. Feel free to create a feature request on Github for this here, this helps us prioritize this feature.

Thank you for the response. Is there another way to align with st.data_editor?

There is an inofficial and undocumented way to change alignment for some types of columns in st.dataframe and st.data_editor:

    pd.DataFrame({"A": [1, 2], "B": [2, 2]}),
    column_config={"A": {"alignment": "center"}, "B": {"alignment": "left"}},

But there is zero guarantee that this will work in future versions, so use this with caution :slight_smile:

1 Like

Thanks! That helps a lot. The columns names can be centered too?

1 Like

Nope, that’s not possible in the current version :frowning: only the content.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.