Skip to content

Conversation

@jrieke
Copy link
Collaborator

@jrieke jrieke commented Dec 27, 2024

Describe your changes

Adds markdown support in st.table for data cells, row index, and column headers. Note that unlike labels, this doesn't have any restrictions on which markdown features can be used. I think table cells are big enough to handle larger markdown elements (such as headers or bullet lists) without looking ugly.

I also changed the empty value from <NA> to a non-breaking space (i.e. an empty cell) because the smaller/greater symbols caused problems with the markdown formatting. Note that for st.dataframe we use None for empty values. In st.table, I think an empty cell looks nicer though, because st.table is less geared towards exploring actual datasets where it might be important to see the actual values and more towards showing a small table of fixed values.

CleanShot 2024-12-27 at 13 23 31

GitHub Issue Link (if applicable)

Closes #8785

Should also leave a note on #6461, which asks for markdown on st.dataframe.

Testing Plan

  • Added an e2e snapshot test for a table with various markdown features.
  • I also tried adding JS unit tests but it's not super easy because we need to add the encoded data for a Markdown table in frontend/lib/src/mocks/arrow/index.ts. Not sure if it's worth doing that given that the e2e test already covers everything.
  • Note that a lot of snapshots changed because of the move from <NA> to an empty cell.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@jrieke jrieke changed the title Allow markdown in st.table [WIP] Allow markdown in st.table Dec 27, 2024
@jrieke jrieke added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Dec 27, 2024
@jrieke
Copy link
Collaborator Author

jrieke commented Dec 27, 2024

Note to myself: should probably add an example in the docstring, since this is a feature we really want to highlight to make the distinction between st.dataframe and st.table more obvious.

@jrieke jrieke changed the title [WIP] Allow markdown in st.table Allow markdown in st.table Dec 27, 2024
@jrieke jrieke marked this pull request as ready for review December 27, 2024 17:26
While ``st.dataframe`` is geared towards large datasets and interactive
data exploration, ``st.table`` is useful to display a small table without
scrolling – e.g. a confusion matrix or a leaderboard. For this reason, it also
supports Markdown formatting.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfc-gh-dmatthews FYI I updated the description here to make it a bit easier to understand the differences.

>>> st.table(df)
.. output::
https://doc-table-markdown.streamlit.app/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfc-gh-dmatthews we still need to deploy an app here or integrate the code into the previous app. Also, feel free to change the code in any way you want!

@sfc-gh-jrieke
Copy link
Contributor

@lukasmasuch I implemented all the comments above, can you give this another look and approve?

static: its entire contents are laid out directly on the page.
While ``st.dataframe`` is geared towards large datasets and interactive
data exploration, ``st.table`` is useful to display a small table without
scrolling – e.g. a confusion matrix or a leaderboard. For this reason, it also
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we also add that st.table is geared towards more style-related customizability? E.g. it also supports a lot more Pandas Styler features compared to st.dataframe.

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 We just merged some other changes related to ArrowTable, it might need merging + recreating of the snapshots.

Also, it probably makes sense to add this to our new markdown_features e2e test as well (e.g. just use a dataframe with a single markdown cell).

@jrieke jrieke merged commit ef82b2d into develop Jan 17, 2025
33 checks passed
@jrieke jrieke deleted the feature/markdown-table branch January 17, 2025 16:38
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
## Describe your changes

Adds markdown support in `st.table` for data cells, row index, and
column headers. Note that unlike labels, this doesn't have any
restrictions on which markdown features can be used. I think table cells
are big enough to handle larger markdown elements (such as headers or
bullet lists) without looking ugly.

I also changed the empty value from `<NA>` to a non-breaking space (i.e.
an empty cell) because the smaller/greater symbols caused problems with
the markdown formatting. Note that for `st.dataframe` we use `None` for
empty values. In `st.table`, I think an empty cell looks nicer though,
because `st.table` is less geared towards exploring actual datasets
where it might be important to see the actual values and more towards
showing a small table of fixed values.

![CleanShot 2024-12-27 at 13 23
31](https://github.com/user-attachments/assets/7d45b45f-b86c-4d12-a858-0a1b9768609b)


## GitHub Issue Link (if applicable)

Closes streamlit#8785 

Should also leave a note on streamlit#6461, which asks for markdown on
`st.dataframe`.

## Testing Plan

- Added an e2e snapshot test for a table with various markdown features.
- I also tried adding JS unit tests but it's not super easy because we
need to add the encoded data for a Markdown table in
`frontend/lib/src/mocks/arrow/index.ts`. Not sure if it's worth doing
that given that the e2e test already covers everything.
- Note that a lot of snapshots changed because of the move from `<NA>`
to an empty cell.

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.

---------

Co-authored-by: Johannes Rieke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support markdown in table cells in st.table

5 participants