How to display st.markdown in a column of st.dataframe?

I am currently developing and running an app locally. I have a column in my dataframe that I have formatted to display markdown, but st.dataframe does not seem to have a column_config feature to execute st.markdown for a column. This would be a highly desirable feature.

  • I can display the dataframe in st.dataframe, but all fields are text and not markdown.
  • I can convert the dataframe to a markdown table, which st.markdown will display appropriately, but no longer has the interactive capability.

import streamlit as st
import pandas as pd

df = pd.DataFrame({
β€˜field1’: [β€˜item1’, β€˜item2’, β€˜item3’],
β€˜display_values’: [β€˜70 :green[↑]’, β€˜11 :red[↓]’, β€˜100 :green[↑]’],
})

df_md = df.to_markdown(index=False)

st.dataframe(df)
st.markdown(df_md)

It seems I would need to add other widgets to reprocess the df_md table in order to make it interactive similiar to st.dataframe.

The column config can be found at st.column_config<!-- --> - Streamlit Docs

Unfortunately, I have tried st.column_config.TextColumn. There is also nothing in the function documentation indicating anything about applying some conversion for Markdown or Latex or how you would specify interpreting column text to Markdown or Latex. The options for the column configuration seem more focused on the st.data_editor aspect to control input tolerances.

When applying the column configuration, nothing changes when applying to columns with Markdown in the column/cells. It displays the text without converting any of the markdown to markdown.

import streamlit as st
import pandas as pd

df = pd.DataFrame({
    'field1': ['name1', 'name2', 'name3'],
    'display_values': ['70 :green[&uarr;]', '11 :red[&darr;]', '100 :green[&uarr;]'],
})

df_md = df.to_markdown(index=False)

st.markdown(df_md)

cfg = {}
cfg['display_values'] = st.column_config.TextColumn(label='Values')
cfg['display_values_1'] = st.column_config.Column(label='Values (alt)')

st.dataframe(df, column_config=cfg)

image

I agree that that would be an appropriate function (st.column_config.TextColumn) to capture that capability, unless another column configuration variation were available.

The alternative seems to create an html table, which also seems somewhat equivalent to the output from st.markdown after converting the dataframe to a markdown table.

ref:

Any news on this ?? have you managed to find a workaround ?

I did not. I think the alternative is to build an html table, which is not what I’m going to do for my project. Its a nice to have if the feature had the capability.

1 Like