posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.44k stars 50 forks source link

Include choice of webdrivers in the `.save()` method #262

Closed rich-iannone closed 2 months ago

rich-iannone commented 3 months ago

Previously, using .save() to capture a table image as a file required a local install of Chrome/Chromium on the host system. While this is a common browser to have, it can be constraining if Chrome is not available (but other common browsers are). In this PR, we increase this to four browsers:

This is exposed as the wd= argument and the default is "chrome" (as before). In my testing on Mac, all of them work very well. There is only minimal differences in rendering and quality is basically the same across the different scaling factors. The cropping works equally well across the four webdrivers tested.

Safari does require that you 'Allow remote automation' in the Develop settings (a warning will be emitted in the console to this effect). Safari doesn't seem to have headless mode, set that command isn't set. Firefox will appear on the screen during capture (but it does shut down gracefully). Safari does something similar but it steals focus on my system.

codecov-commenter commented 3 months ago

Codecov Report

Attention: Patch coverage is 62.50000% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 81.47%. Comparing base (b22072d) to head (d02be48).

Files Patch % Lines
great_tables/_export.py 62.50% 9 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #262 +/- ## ========================================== - Coverage 81.62% 81.47% -0.16% ========================================== Files 40 40 Lines 4229 4242 +13 ========================================== + Hits 3452 3456 +4 - Misses 777 786 +9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Yasin197 commented 3 months ago

Will this work in a Linux environment?

rich-iannone commented 3 months ago

Will this work in a Linux environment?

It should but we'd need to test it. We won't merge until it is tested with Chrome, Firefox, and Edge in some Linuxes.

rich-iannone commented 2 months ago

In testing on Mac, here is the code used (to create individual files, changing driver to modify the webdriver used):


import great_tables as gt
from great_tables.data import sp500

start_date = "2010-06-07"
end_date = "2010-06-14"

sp500_mini = sp500[(sp500["date"] >= start_date) & (sp500["date"] <= end_date)]

driver="chrome"

(
    gt.GT(data=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")
    .save(f"test-{driver}.png", scale=1, wd=driver)
)

Here are the results on Mac.

chrome: test-chrome

safari: test-safari

firefox: test-firefox

edge: test-edge

rich-iannone commented 2 months ago

I like "web_driver" and totally agree that the current name is too short and non-descriptive. Will make that change soon!

edit: reconsidered this and "web_driver" now appeals more.