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

Improve HTML representation of tables #233

Merged
merged 17 commits into from
Mar 13, 2024
Merged

Improve HTML representation of tables #233

merged 17 commits into from
Mar 13, 2024

Conversation

rich-iannone
Copy link
Member

@rich-iannone rich-iannone commented Mar 7, 2024

This PR adds the option to generate a complete HTML page around the emitted table fragment. And this vastly improves the printing of a table in the vscode jupyter notebook environment by raising the specificity of the tables CSS rules (in the <style> block). We also detect whether rendering is occurring in a Quarto document and, in that case, the compiled CSS is kept as is.

Fixes: #228

@github-actions github-actions bot temporarily deployed to pr-233 March 7, 2024 22:39 Destroyed
@rich-iannone rich-iannone marked this pull request as ready for review March 8, 2024 17:36
great_tables/gt.py Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pr-233 March 8, 2024 19:56 Destroyed
@github-actions github-actions bot temporarily deployed to pr-233 March 8, 2024 20:40 Destroyed
@github-actions github-actions bot temporarily deployed to pr-233 March 8, 2024 20:44 Destroyed
Copy link
Collaborator

@machow machow left a comment

Choose a reason for hiding this comment

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

There are no tests in this PR. Do you mind adding some?

From us pairing, it seems useful to have some machinery to mock environments. That way we can sanity check what gets rendered in different places.

great_tables/gt.py Outdated Show resolved Hide resolved
great_tables/gt.py Outdated Show resolved Hide resolved
if context == "html" and make_page:
html_table = built_table._render_as_html(
make_page=make_page,
page_background_color=page_background_color,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It appears that triggering page_background_color affects the background of the whole notebook:

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if page_background_color should be an option (e.g. in tab_options())

<html lang="en">
<head>
<meta charset="utf-8"/>
<style>body {{ background-color:{page_background_color};}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I added a screenshot in another place, but it seems like we'd need a more targeted style here. E.g. we could give body an id or something similar.

great_tables/gt.py Outdated Show resolved Hide resolved
great_tables/gt.py Outdated Show resolved Hide resolved
great_tables/gt.py Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pr-233 March 12, 2024 18:15 Destroyed
@machow
Copy link
Collaborator

machow commented Mar 12, 2024

From pairing w/ Rich, I've consolidated the code for inferring the IDE environment into the _render.py submodule, and hard-coded the IDE environment specific flags there.

(Rich mentioned he'll pick it up from here!)

@github-actions github-actions bot temporarily deployed to pr-233 March 12, 2024 20:15 Destroyed
@github-actions github-actions bot temporarily deployed to pr-233 March 12, 2024 21:03 Destroyed
@github-actions github-actions bot temporarily deployed to pr-233 March 12, 2024 21:12 Destroyed
@github-actions github-actions bot temporarily deployed to pr-233 March 12, 2024 21:14 Destroyed
assert snapshot == html_repr_output


@mock.patch.dict(os.environ, {"QUARTO_BIN_PATH": "1"}, clear=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is neat!

Copy link
Collaborator

@machow machow left a comment

Choose a reason for hiding this comment

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

This is looking good -- the one big note I left is that the css style setting body background to white is too broad--it can affect the entire page (similar to the screenshot I posted that turned the page blue).

If it can be removed, then feel free to remove and merge. (You'll know better than me whether that's possible ;)

<html lang="en">
<head>
<meta charset="utf-8"/>
<style>body {{ background-color:white; }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This styles every body element on the page to white (including the overall body element for the page). We need a more specifically scoped css style. If we want to set only the body element defined here to white, then we need to either...

  • specify the style inline
  • give the body element a unique id and set the style on that

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, didn't go all the way with this. I'm going to remove it entirely.

@rich-iannone
Copy link
Member Author

@isabelizimm @machow thank you for your help with this PR! Going to merge now but there should be many more improvements in this particular area down the road.

@rich-iannone rich-iannone merged commit 13d652e into main Mar 13, 2024
7 checks passed
@rich-iannone rich-iannone deleted the html-repr-add-page branch March 13, 2024 14:50
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 this pull request may close these issues.

Wrap rendered html table in html or body tags
3 participants