Skip to content
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

Return browsable gt object in Python repl #100

Closed
jooyoungseo opened this issue Dec 25, 2023 · 5 comments · Fixed by #379
Closed

Return browsable gt object in Python repl #100

jooyoungseo opened this issue Dec 25, 2023 · 5 comments · Fixed by #379
Assignees

Comments

@jooyoungseo
Copy link

Thanks for this great package! I am suggesting one feature request below.

In R {gt} package, gt() object returns browsable table in user's default browser. This is very convenient way for screen reader users to navigate data table in an alternative way. Could you please consider this in Python package as well?

Currently, GT() method returns html code in Python repl. Browsable GT object might be more useful in an interactive terminal from end-user's perspective.

@machow
Copy link
Collaborator

machow commented Jan 2, 2024

Thanks for looking into this issue! I've been looking around for python libraries that do something similar, and it seems like plotly might be a good example of this:

import plotly.express as px

fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])

# opens a browser window
fig.show()

Since the gt for R opens a browser aimed at a temporary .html file, we should be able to do the same. WDYT of that approach? In python, I wonder if we should add a method, like .preview(), that triggers this behavior.

I think the .__repr__ method triggering a browser window to open might be surprising to python users, but a .preview() method matches the behavior of a lot of tools. For plotly, it looks like they do trigger a browser window when you dump to console, but only for IPython, not for the python repl (there, you have to use fig.show())...

@jooyoungseo
Copy link
Author

Maybe, I could be wrong, but in R, {gt} seems to rely on {htmltools} and gt::gt() appears to return htmltools::browsable() object.

I created a feature request posit-dev/py-htmltools#79 to ask if {py-htmltools} could possibly support htmltools.browsable() methods. It would be great if {great_tables} depends on {py-htmltools} once it gets more reliable.

@jooyoungseo
Copy link
Author

jooyoungseo commented Jan 2, 2024

@machow -- I have just learned from @cpsievert that we could use show() method against {py-htmltools} object. What if {great_tables} depends on {py-htmltools} for this feature and beyond?

@machow
Copy link
Collaborator

machow commented Jan 3, 2024

Great Tables uses htmltools, so this is perfect! I was able to get it to appear in the browser using this code in the IPython console...

from great_tables import GT, exibble
from htmltools import HTML, TagList

res = GT(exibble).render("html")
el = HTML(res)

TagList(el).show("browser")

Note that I had to pass "browser" as an argument. The default argument of "auto" didn't seem to do anything.

It seems like at the very least we should add a .show() or .preview() method, which holds the logic for viewing the table anywhere (jupyterlab, IPython console, etc..). This could use something similar to the code above.

@cpsievert
Copy link

The default argument of "auto" didn't seem to do anything.

That seems like a bug. If you can pinpoint the reason why it doesn't do anything, a issue/PR in htmltools would be much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants