great_tables: rendered html should go to viewer
Positron Version:
Positron Version: 2024.01.0 (Universal) build 162 Code - OSS Version: 1.85.0 Commit: aeb47f532448b4f691fe7432f8b6938bcb565d34 Date: 2024-01-17T17:34:28.863Z Electron: 25.9.7 ElectronBuildId: undefined Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Darwin arm64 23.2.0
Steps to reproduce the issue:
pip install great_tables- Run the code below
# note that you could also use pandas here
import polars as pl
from great_tables import GT
df = pl.DataFrame({"x": [1,2,3]})
GT(df)
What did you expect to happen?
Similar to the gt R package in RStudio and Positron, it would be nice if the output for the python package displayed in the Viewer pane. However, it gets put into the console output (still formatted at HTML though, which is handy!). We're happy to implement any hooks / checks to handle this on the python side!
This is happening specifically because Great Table's html output does not include html, body, or script tags, which Positron uses to distinguish what should go in the console vs. Viewer. After pairing with @machow, there could be changes on the Great Tables side to include these tags OR changes on the Positron side to look for a Great Tables identifying tag.
Following https://github.com/posit-dev/great-tables/pull/233 -- there will be a fix in great_tables to get this output to the right place!
Great tables PR is merged-- there is now infrastructure in place to put the output in the Viewer pane. It is not turned on right now, since it will require code in great_tables to be something like ipython.get_ipython().__class__.__name__ == 'PositronShell' to set the correct HTML output.
So do I understand correctly that it is not (easily) possible for us to get great tables into the Positron viewer pane before we can do a Positron-specific PR to the package? Should we move this issue to Release Candidate?
Correct, the PR would have to include the name Positron, so this can go anytime after Public Beta.
It appears that even when using great-tables v0.10 the output is still printed to the console instead of the Viewer.
Is this an action on our end or something we can ask of @machow ?
This is an action on our end; the decision concerning what HTML gets rendered in the Console vs. what gets promoted to the Viewer is based on heuristics, so we would just need to tweak those.
There are heuristics in great_tables depending on what IDE the table is being rendered in. Right now, it will create a full html page if it is detected that the user is running in Positron, which I believe aligns with Positron's heuristics on what is Viewer-worthy.
with great_tables==0.10.0 I am able to see a table populate the Viewer pane, although there is a lot of context being printed with the call we could clean up 😅 Is there a reprex for it printing in the console?
I am seeing the printing to console, and for some reason last night I swear it wasn't bringing the Viewer into focus or displaying 🤔
The below is working just fine currently.
#minimal
import pandas as pd
from great_tables import GT
df = pd.DataFrame({"x": [1,2,3]})
GT(df)
# more advanced
from great_tables import GT
from great_tables.data import sp500
# Define the start and end dates for the data range
start_date = "2010-06-07"
end_date = "2010-06-14"
# Filter sp500 using Pandas to dates between `start_date` and `end_date`
sp500_mini = sp500[(sp500["date"] >= start_date) & (sp500["date"] <= end_date)]
# Create a display table based on the `sp500_mini` table data
(
GT(sp500_mini)
.tab_header(title="S&P 500", subtitle=f"{start_date} to {end_date}")
.fmt_currency(columns=["open", "high", "low", "close"])
.fmt_date(columns="date", date_style="wd_m_day_year")
.fmt_number(columns="volume", compact=True)
.cols_hide(columns="adj_close")
)
>>> from great_tables import GT
... from great_tables.data import sp500
...
... # Define the start and end dates for the data range
... start_date = "2010-06-07"
... end_date = "2010-06-14"
...
... # Filter sp500 using Pandas to dates between `start_date` and `end_date`
... sp500_mini = sp500[(sp500["date"] >= start_date) & (sp500["date"] <= end_date)]
...
... # Create a display table based on the `sp500_mini` table data
... (
... GT(sp500_mini)
... .tab_header(title="S&P 500", subtitle=f"{start_date} to {end_date}")
... .fmt_currency(columns=["open", "high", "low", "close"])
... .fmt_date(columns="date", date_style="wd_m_day_year")
... .fmt_number(columns="volume", compact=True)
... .cols_hide(columns="adj_close")
... )
GT(_tbl_data= date open high low close volume adj_close
1398 2010-06-14 1095.0000 1105.91 1089.03 1089.6300 4.425830e+09 1089.6300
1399 2010-06-11 1082.6500 1092.25 1077.12 1091.6000 4.059280e+09 1091.6000
1400 2010-06-10 1058.7700 1087.85 1058.77 1086.8400 5.144780e+09 1086.8400
1401 2010-06-09 1062.7500 1077.74 1052.25 1055.6899 5.983200e+09 1055.6899
1402 2010-06-08 1050.8101 1063.15 1042.17 1062.0000 6.192750e+09 1062.0000
1403 2010-06-07 1065.8400 1071.36 1049.86 1050.4700 5.467560e+09 1050.4700, _body=<great_tables._gt_data.Body object at 0x1447c66f0>, _boxhead=Boxhead([ColInfo(var='date', type=<ColInfoTypeEnum.default: 1>, column_label='date', column_align='right', column_width=None), ColInfo(var='open', type=<ColInfoTypeEnum.default: 1>, column_label='open', column_align='right', column_width=None), ColInfo(var='high', type=<ColInfoTypeEnum.default: 1>, column_label='high', column_align='right', column_width=None), ColInfo(var='low', type=<ColInfoTypeEnum.default: 1>, column_label='low', column_align='right', column_width=None), ColInfo(var='close', type=<ColInfoTypeEnum.default: 1>, column_label='close', column_align='right', column_width=None), ColInfo(var='volume', type=<ColInfoTypeEnum.default: 1>, column_label='volume', column_align='right', column_width=None), ColInfo(var='adj_close', type=<ColInfoTypeEnum.hidden: 4>, column_label='adj_close', column_align='right', column_width=None)]), _stub=<great_tables._gt_data.Stub object at 0x1447c4f80>, _spanners=Spanners([]), _heading=Heading(title='S&P 500', subtitle='2010-06-07 to 2010-06-14', preheader=None), _stubhead=None, _source_notes=[], _footnotes=[], _styles=[], _locale=<great_tables._gt_data.Locale object at 0x1447eb590>, _formats=[<great_tables._gt_data.FormatInfo object at 0x1447b4140>, <great_tables._gt_data.FormatInfo object at 0x1447c7f80>, <great_tables._gt_data.FormatInfo object at 0x1447eb1d0>], _substitutions=[], _options=Options(table_id=OptionsInfo(scss=False, category='table', type='value', value=None), table_caption=OptionsInfo(scss=False, category='table', type='value', value=None), table_width=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_layout=OptionsInfo(scss=True, category='table', type='value', value='fixed'), table_margin_left=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_margin_right=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_background_color=OptionsInfo(scss=True, category='table', type='value', value='#FFFFFF'), table_font_names=OptionsInfo(scss=False, category='table', type='values', value=['-apple-system', 'BlinkMacSystemFont', 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Helvetica Neue', 'Fira Sans', 'Droid Sans', 'Arial', 'sans-serif']), table_font_size=OptionsInfo(scss=True, category='table', type='px', value='16px'), table_font_weight=OptionsInfo(scss=True, category='table', type='value', value='normal'), table_font_style=OptionsInfo(scss=True, category='table', type='value', value='normal'), table_font_color=OptionsInfo(scss=True, category='table', type='value', value='#333333'), table_font_color_light=OptionsInfo(scss=True, category='table', type='value', value='#FFFFFF'), table_border_top_include=OptionsInfo(scss=False, category='table', type='boolean', value=True), table_border_top_style=OptionsInfo(scss=True, category='table', type='value', value='solid'), table_border_top_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_top_color=OptionsInfo(scss=True, category='table', type='value', value='#A8A8A8'), table_border_right_style=OptionsInfo(scss=True, category='table', type='value', value='none'), table_border_right_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_right_color=OptionsInfo(scss=True, category='table', type='value', value='#D3D3D3'), table_border_bottom_include=OptionsInfo(scss=False, category='table', type='boolean', value=True), table_border_bottom_style=OptionsInfo(scss=True, category='table', type='value', value='solid'), table_border_bottom_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_bottom_color=OptionsInfo(scss=True, category='table', type='value', value='#A8A8A8'), table_border_left_style=OptionsInfo(scss=True, category='table', type='value', value='none'), table_border_left_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_left_color=OptionsInfo(scss=True, category='table', type='value', value='#D3D3D3'), heading_background_color=OptionsInfo(scss=True, category='heading', type='value', value=None), heading_align=OptionsInfo(scss=True, category='heading', type='value', value='center'), heading_title_font_size=OptionsInfo(scss=True, category='heading', type='px', value='125%'), heading_title_font_weight=OptionsInfo(scss=True, category='heading', type='value', value='initial'), heading_subtitle_font_size=OptionsInfo(scss=True, category='heading', type='px', value='85%'), heading_subtitle_font_weight=OptionsInfo(scss=True, category='heading', type='value', value='initial'), heading_padding=OptionsInfo(scss=True, category='heading', type='px', value='4px'), heading_padding_horizontal=OptionsInfo(scss=True, category='heading', type='px', value='5px'), heading_border_bottom_style=OptionsInfo(scss=True, category='heading', type='value', value='solid'), heading_border_bottom_width=OptionsInfo(scss=True, category='heading', type='px', value='2px'), heading_border_bottom_color=OptionsInfo(scss=True, category='heading', type='value', value='#D3D3D3'), heading_border_lr_style=OptionsInfo(scss=True, category='heading', type='value', value='none'), heading_border_lr_width=OptionsInfo(scss=True, category='heading', type='px', value='1px'), heading_border_lr_color=OptionsInfo(scss=True, category='heading', type='value', value='#D3D3D3'), column_labels_background_color=OptionsInfo(scss=True, category='column_labels', type='value', value=None), column_labels_font_size=OptionsInfo(scss=True, category='column_labels', type='px', value='100%'), column_labels_font_weight=OptionsInfo(scss=True, category='column_labels', type='value', value='normal'), column_labels_text_transform=OptionsInfo(scss=True, category='column_labels', type='value', value='inherit'), column_labels_padding=OptionsInfo(scss=True, category='column_labels', type='px', value='5px'), column_labels_padding_horizontal=OptionsInfo(scss=True, category='column_labels', type='px', value='5px'), column_labels_vlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='none'), column_labels_vlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='1px'), column_labels_vlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='#D3D3D3'), column_labels_border_top_style=OptionsInfo(scss=True, category='column_labels', type='value', value='solid'), column_labels_border_top_width=OptionsInfo(scss=True, category='column_labels', type='px', value='2px'), column_labels_border_top_color=OptionsInfo(scss=True, category='column_labels', type='value', value='#D3D3D3'), column_labels_border_bottom_style=OptionsInfo(scss=True, category='column_labels', type='value', value='solid'), column_labels_border_bottom_width=OptionsInfo(scss=True, category='column_labels', type='px', value='2px'), column_labels_border_bottom_color=OptionsInfo(scss=True, category='column_labels', type='value', value='#D3D3D3'), column_labels_border_lr_style=OptionsInfo(scss=True, category='column_labels', type='value', value='none'), column_labels_border_lr_width=OptionsInfo(scss=True, category='column_labels', type='px', value='1px'), column_labels_border_lr_color=OptionsInfo(scss=True, category='column_labels', type='value', value='#D3D3D3'), column_labels_hidden=OptionsInfo(scss=False, category='column_labels', type='boolean', value=False), row_group_background_color=OptionsInfo(scss=True, category='row_group', type='value', value=None), row_group_font_size=OptionsInfo(scss=True, category='row_group', type='px', value='100%'), row_group_font_weight=OptionsInfo(scss=True, category='row_group', type='value', value='initial'), row_group_text_transform=OptionsInfo(scss=True, category='row_group', type='value', value='inherit'), row_group_padding=OptionsInfo(scss=True, category='row_group', type='px', value='8px'), row_group_padding_horizontal=OptionsInfo(scss=True, category='row_group', type='px', value='5px'), row_group_border_top_style=OptionsInfo(scss=True, category='row_group', type='value', value='solid'), row_group_border_top_width=OptionsInfo(scss=True, category='row_group', type='px', value='2px'), row_group_border_top_color=OptionsInfo(scss=True, category='row_group', type='value', value='#D3D3D3'), row_group_border_right_style=OptionsInfo(scss=True, category='row_group', type='value', value='none'), row_group_border_right_width=OptionsInfo(scss=True, category='row_group', type='px', value='1px'), row_group_border_right_color=OptionsInfo(scss=True, category='row_group', type='value', value='#D3D3D3'), row_group_border_bottom_style=OptionsInfo(scss=True, category='row_group', type='value', value='solid'), row_group_border_bottom_width=OptionsInfo(scss=True, category='row_group', type='px', value='2px'), row_group_border_bottom_color=OptionsInfo(scss=True, category='row_group', type='value', value='#D3D3D3'), row_group_border_left_style=OptionsInfo(scss=True, category='row_group', type='value', value='none'), row_group_border_left_width=OptionsInfo(scss=True, category='row_group', type='px', value='1px'), row_group_border_left_color=OptionsInfo(scss=True, category='row_group', type='value', value='#D3D3D3'), row_group_as_column=OptionsInfo(scss=False, category='row_group', type='boolean', value=False), table_body_hlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='solid'), table_body_hlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='1px'), table_body_hlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='#D3D3D3'), table_body_vlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='none'), table_body_vlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='1px'), table_body_vlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='#D3D3D3'), table_body_border_top_style=OptionsInfo(scss=True, category='table_body', type='value', value='solid'), table_body_border_top_width=OptionsInfo(scss=True, category='table_body', type='px', value='2px'), table_body_border_top_color=OptionsInfo(scss=True, category='table_body', type='value', value='#D3D3D3'), table_body_border_bottom_style=OptionsInfo(scss=True, category='table_body', type='value', value='solid'), table_body_border_bottom_width=OptionsInfo(scss=True, category='table_body', type='px', value='2px'), table_body_border_bottom_color=OptionsInfo(scss=True, category='table_body', type='value', value='#D3D3D3'), data_row_padding=OptionsInfo(scss=True, category='data_row', type='px', value='8px'), data_row_padding_horizontal=OptionsInfo(scss=True, category='data_row', type='px', value='5px'), stub_background_color=OptionsInfo(scss=True, category='stub', type='value', value=None), stub_font_size=OptionsInfo(scss=True, category='stub', type='px', value='100%'), stub_font_weight=OptionsInfo(scss=True, category='stub', type='value', value='initial'), stub_text_transform=OptionsInfo(scss=True, category='stub', type='value', value='inherit'), stub_border_style=OptionsInfo(scss=True, category='stub', type='value', value='solid'), stub_border_width=OptionsInfo(scss=True, category='stub', type='px', value='2px'), stub_border_color=OptionsInfo(scss=True, category='stub', type='value', value='#D3D3D3'), stub_row_group_background_color=OptionsInfo(scss=True, category='stub', type='value', value=None), stub_row_group_font_size=OptionsInfo(scss=True, category='stub', type='px', value='100%'), stub_row_group_font_weight=OptionsInfo(scss=True, category='stub', type='value', value='initial'), stub_row_group_text_transform=OptionsInfo(scss=True, category='stub', type='value', value='inherit'), stub_row_group_border_style=OptionsInfo(scss=True, category='stub', type='value', value='solid'), stub_row_group_border_width=OptionsInfo(scss=True, category='stub', type='px', value='2px'), stub_row_group_border_color=OptionsInfo(scss=True, category='stub', type='value', value='#D3D3D3'), source_notes_padding=OptionsInfo(scss=True, category='source_notes', type='px', value='4px'), source_notes_padding_horizontal=OptionsInfo(scss=True, category='source_notes', type='px', value='5px'), source_notes_background_color=OptionsInfo(scss=True, category='source_notes', type='value', value=None), source_notes_font_size=OptionsInfo(scss=True, category='source_notes', type='px', value='90%'), source_notes_border_bottom_style=OptionsInfo(scss=True, category='source_notes', type='value', value='none'), source_notes_border_bottom_width=OptionsInfo(scss=True, category='source_notes', type='px', value='2px'), source_notes_border_bottom_color=OptionsInfo(scss=True, category='source_notes', type='value', value='#D3D3D3'), source_notes_border_lr_style=OptionsInfo(scss=True, category='source_notes', type='value', value='none'), source_notes_border_lr_width=OptionsInfo(scss=True, category='source_notes', type='px', value='2px'), source_notes_border_lr_color=OptionsInfo(scss=True, category='source_notes', type='value', value='#D3D3D3'), source_notes_multiline=OptionsInfo(scss=False, category='source_notes', type='boolean', value=True), source_notes_sep=OptionsInfo(scss=False, category='source_notes', type='value', value=' '), container_width=OptionsInfo(scss=False, category='container', type='px', value='auto'), container_height=OptionsInfo(scss=False, category='container', type='px', value='auto'), container_padding_x=OptionsInfo(scss=False, category='container', type='px', value='0px'), container_padding_y=OptionsInfo(scss=False, category='container', type='px', value='10px'), container_overflow_x=OptionsInfo(scss=False, category='container', type='overflow', value='auto'), container_overflow_y=OptionsInfo(scss=False, category='container', type='overflow', value='auto'), quarto_disable_processing=OptionsInfo(scss=False, category='quarto', type='logical', value=False), quarto_use_bootstrap=OptionsInfo(scss=False, category='quarto', type='logical', value=False)), _has_built=False)
>>>
As of July 23, 2024 I can't get great tables plots to show up in the console. Did great tables to a release to fix this? @machow
I can't get great tables plots to show up in the console.
Are you wanting the table to be in the Viewer pane or the Console? I believe the expected behavior at this point is that the table goes to the viewer pane
That was a confusingly worded way of saying: I think this is fixed now. I want them to show up in the viewer pane.
In latest build, I'm still seeing a bunch of HTML content printed to console but not "used", although the table is printing to the Viewer pane.
Positron Version: 2024.07.0 (Universal) build 89 Code - OSS Version: 1.91.0 Commit: 08b25a7c9a8ce879674850f76728517302bc91e3 Date: 2024-07-23T04:47:51.330Z Electron: 29.4.0 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Darwin arm64 23.5.0
pip freeze | grep great
great-tables==0.10.0
https://github.com/user-attachments/assets/510f2246-c9b7-4fdc-bfef-36df22eb0d8b
That looks like GT's console representation. If you were to output a GT object in the IPython shell, that's what it would produce. In jupyter lab something like this happens:
- trigger all kinds of
_repr_*_()methods - decide on the one to use (e.g. the output of
_repr_html_()) - don't use the other ones
It seems like maybe positron might be keeping the console repr in step (3)? I could have this super wrong, and am happy to do whatever is useful!
Verified Fixed
Positron Version(s) : 2024.07.0-113
OS Version : OSX
Test scenario(s)
Looks good from console and notebook.
Link(s) to TestRail test cases run or created: N/A