-
Notifications
You must be signed in to change notification settings - Fork 4k
Add support for Pandas styler tooltips to st.table
#10561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Pandas styler tooltips to st.table
#10561
Conversation
| // we need to convert the specific HTML element (used for tooltips) from | ||
| // the display value into an actual span element. | ||
| formattedContent = formattedContent.replace( | ||
| `<span class="pd-t"></span>`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be best to use a regex to replace it only if it is at the end of formattedContent? I doubt it will ever make a difference, but it makes the code consistent with the check for formattedContent.endsWith(`<span class="pd-t"></span>`).
| `<span class="pd-t"></span>`, | |
| /<span class="pd-t"><\/span>$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that should work as well 👍 Changed it
JosephMarinier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Thank you very much!
Co-authored-by: Joseph Marinier <[email protected]>
| formattedContent && | ||
| formattedContent.endsWith(`<span class="pd-t"></span>`) | ||
| ) { | ||
| // This is a bit hacky, but to support the Pandas Styler's tooltip feature, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit ugly, but it seems like the likelihood that we enter this block as a false positive is extremely low.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, unfortunately the ugly part already happens in the hacky way were are parsing pandas styler display values out of the html representation of the dataframe :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems more likely that one day we may no longer enter this block if Pandas makes changes, for example to the CSS class name. No catastrophic consequences, just no tooltips. I'll let you know if I catch that happening. 😜
Thanks for the review!
Describe your changes
Adds support for Pandas Styler tooltips to
st.table:Screen.Recording.2025-02-28.at.14.31.58.mov
GitHub Issue Link (if applicable)
st.dataframe(styler)andst.table(styler)raise anAttributeErrorwhen usingstyler.set_tooltips()#10553Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.