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?
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
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]})
st.data_editor(df.style.set_table_styles(styles))
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
:
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
Thanks! That helps a lot. The columns names can be centered too?
Nope, thatâs not possible in the current version only the content.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.