Skip to content

Add border parameter to st.table#11796

Merged
jrieke merged 33 commits intodevelopfrom
feature/borderless-table
Aug 27, 2025
Merged

Add border parameter to st.table#11796
jrieke merged 33 commits intodevelopfrom
feature/borderless-table

Conversation

@jrieke
Copy link
Copy Markdown
Collaborator

@jrieke jrieke commented Jun 27, 2025

Describe your changes

Adds a border parameter to st.table, which allows creating different table styles:

Screenshot 2025-06-27 at 16 27 53

Demo app to show it in combination with other st.table features:

Screenshot 2025-06-27 at 16 27 37

GitHub Issue Link (if applicable)

Closes #11795

Testing Plan

  • Unit Tests (JS and/or Python) ✅
  • E2E Tests ✅

Contribution License Agreement

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

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Jun 27, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 27, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11796/streamlit-1.48.1-py3-none-any.whl
🕹️ Preview app pr-11796.streamlit.app (☁️ Deploy here if not accessible)

@jrieke jrieke requested a review from Copilot June 27, 2025 13:18

This comment was marked as outdated.

@jrieke jrieke added security-assessment-completed impact:users PR changes affect end users change:other PR contains other type of change change:feature PR contains new feature or enhancement implementation and removed change:other PR contains other type of change labels Jun 27, 2025
Comment on lines +49 to +50
// Whether to show borders around the table and between cells
bool border = 14;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's very annoying/confusing that dataframe, data editor, table, charts, etc, are all reusing this arrow proto message. I think we need to get to a better solution here before adding a lot of new parameters...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Have been planning to think about a good solution for this. But the main problem is the backwards compatibility that makes it nearly impossible to do any reasonable change here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But I'm hoping that we can soon scrape the backwards compatibility (with SiS vnext) and finally do a real refactoring of our protos.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hm damn. So no way to move forward with this PR before we do that refactoring?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yeah I think we can move forward. But maybe add some comments that its table only prop.

).toBeInTheDocument()
})

it("renders with all borders when border=true", () => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if we need so many frontend tests here or if it's better to just have the e2e snapshot tests...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My personal preference is to have e2e tests for style aspects. But probably fine to leave those in.

This comment was marked as outdated.

Examples
--------
**Example 1: Display a simple dataframe as a static table**
**Example 1: Display a confusion matrix**
Copy link
Copy Markdown
Collaborator Author

@jrieke jrieke Jun 27, 2025

Choose a reason for hiding this comment

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

Note that I updated the two examples here to show some more real-world use cases for st.table. I think this is important so we differentiate it from st.dataframe. @sfc-gh-dmatthews your call whether we should edit something here. We also need to update the demo apps.

I'd also love to add a 3rd example with border=None that shows how you can use a borderless table for "layout" purposes (e.g. to show some metric names on the left and values on the right side), but I think we first need hide_index and hide_header to make that look good (and ideally hide both by default if there's no information in the index/header), so I left it out for now.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is what the 2 examples look like:

Screenshot 2025-06-28 at 01 30 27

@jrieke jrieke marked this pull request as ready for review June 27, 2025 23:31
@jrieke jrieke requested a review from a team as a code owner June 27, 2025 23:31
@jrieke jrieke mentioned this pull request Jun 30, 2025
2 tasks
Comment on lines +147 to +149
/** Whether to show borders around the table and between cells. */
private readonly _border: Arrow.BorderMode

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we want to pass this info through quiver, since quiver should only deal with the arrow data. Instead, it would be better to pass in the full element the same way as its done with the dataframe here:

element={arrowProto}
data={node.quiverElement}

which needs a bit refactoring by moving the current element prop to data and adding a new element prop that has the full proto message.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

✅ Done, I refactored it so it doesn't use Quiver anymore. I also cross-checked with the dataframe implementation that the refactored part uses the same structure but would be great if you could give this another quick look.

borderRadius: theme.radii.default,
overflow: "auto",
}))
export const StyledTableBorder = styled.div<{ $border: Arrow.BorderMode }>(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Was there a specific reason why you used $ as a prefix? Did the browser complain? I believe it's to prevent the property from being forwarded to an HTML property with the same name.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

✅ I don't remember anymore but I changed everything to use borderMode / border_mode now (except for the public Python API), then we don't run into these conflicts + it's more consistent with the ArrowProto.BorderMode type + it's more similar to what we do for selection mode / editing mode.

Copy link
Copy Markdown
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.

Overall LGTM, but the aspect with how the border info is passed in needs a change.

@jrieke jrieke requested a review from Copilot August 26, 2025 21:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a border parameter to st.table that allows users to control how table borders are displayed. The parameter accepts True (all borders), False (no borders), or "horizontal" (only horizontal borders between rows).

  • Adds new BorderMode enum to the Arrow protobuf with three values: ALL, NONE, and HORIZONTAL
  • Implements border parsing and validation logic in the Python backend
  • Updates frontend components to conditionally render borders and adjust padding/alignment based on the border mode

Reviewed Changes

Copilot reviewed 9 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
proto/streamlit/proto/Arrow.proto Adds BorderMode enum and border_mode field to Arrow message
lib/streamlit/elements/arrow.py Implements border parameter parsing and adds it to st.table function
lib/tests/streamlit/elements/arrow_table_test.py Adds unit tests for border parameter validation and proto mapping
frontend/lib/src/components/elements/ArrowTable/ArrowTable.tsx Updates component to accept and use border mode for rendering logic
frontend/lib/src/components/elements/ArrowTable/ArrowTable.test.tsx Adds frontend tests for different border modes
frontend/lib/src/components/elements/ArrowTable/styled-components.ts Implements conditional CSS styling based on border mode
frontend/lib/src/components/core/Block/ElementNodeRenderer.tsx Updates element renderer to pass Arrow proto to ArrowTable component
e2e_playwright/st_table.py Adds examples showcasing the new border parameter
e2e_playwright/st_table_test.py Updates test to account for additional table elements

Copy link
Copy Markdown
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 👍 a couple of comments

@jrieke jrieke enabled auto-merge (squash) August 27, 2025 17:52
@jrieke jrieke merged commit 2087ea1 into develop Aug 27, 2025
37 checks passed
@jrieke jrieke deleted the feature/borderless-table branch August 27, 2025 19:29
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Borderless st.table

5 participants