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

Issue when attempting to save #596

Open
HansMellman opened this issue Feb 3, 2025 · 3 comments
Open

Issue when attempting to save #596

HansMellman opened this issue Feb 3, 2025 · 3 comments

Comments

@HansMellman
Copy link

Code

(
    GT(qb)
    .tab_header(
        title=md("<img src='https://i.imgur.com/xJYzCF8.png' width='90' height='90' style='vertical-align: middle;'> &#x1F3C8; **Analysis by Position Group** &#x1F3C8; <img src='https://i.imgur.com/xJYzCF8.png' width='90' height='90' style='vertical-align: middle;'>"), ## add small footballs to the title. ## these characters cause issues when saving. 
        subtitle=md("_**2065 Regular Season**_")
    )
    .fmt_image(
        columns='Team',
        path=analysis_path,
        file_pattern="{}.png"
    )
    .cols_align(
        align="center", columns=None
    )
    .cols_label(
        Team = (" "),
        Position_Group = (" "),
        Intelligence = ("Intel"),
        Performance_Grade = ("Performance"),
        Current_Overall = ("Current"),
        Future_Overall = ("Future"),
        PenaltiesCommitted = ("Penalties"),
        Pedigree_Percentage = ("Pedigree"),
        Intelligence_vs_league_avg = ("Int"),
        PenaltiesCommitted_vs_league_avg = ("Pen"),
        Performance_Grade_vs_league_avg = ("Perf"),
        Current_Overall_vs_league_avg = ("Curr"),
        Future_Overall_vs_league_avg = ("Fut"),
        Experience_vs_league_avg = ("Exp"),
        Pedigree_Percentage_vs_league_avg = ("Pedigree")
    )
    .tab_options(
        container_width = "100%",
        heading_background_color="#990033",
        table_border_top_color="#990033",
        table_font_names="Calibri",
        table_font_size="20px"
    )
    .tab_style(
        style=style.fill(
            color=map_colour_analysis),
        locations=loc.body("Position_Group")
        )
    .tab_style(
        style=style.text(
            color=text_colour_analysis),
        locations=loc.body("Position_Group")
        )
    .tab_spanner(
        label=md('**Cumulative**'),
        columns=['PenaltiesCommitted', 'Pedigree_Percentage']
    )
    .tab_spanner(
        label=md('**Group Averages**'),
        columns=['Intelligence', 'Performance_Grade', 'Current_Overall', 'Future_Overall', 'Experience']
    )
    .tab_spanner(
        label=md('**Versus League Average**'), ### MAYBE THE ORDER HERE NEEDS TO BE CHANGED TO HAVE PENALTIES SECOND LAST LIKE THE LEFT HAND COLUMNS?
        columns=['Intelligence_vs_league_avg', 'Performance_Grade_vs_league_avg', 'Current_Overall_vs_league_avg', 'Future_Overall_vs_league_avg', 'Experience_vs_league_avg','PenaltiesCommitted_vs_league_avg', 'Pedigree_Percentage_vs_league_avg']
    )
    .fmt_percent(['Intelligence_vs_league_avg', 'PenaltiesCommitted_vs_league_avg', 'Performance_Grade_vs_league_avg', 'Current_Overall_vs_league_avg', 'Future_Overall_vs_league_avg', 'Experience_vs_league_avg', 'Pedigree_Percentage_vs_league_avg'], decimals=1, drop_trailing_zeros=True, scale_values=False)
    .data_color(
        columns=['Intelligence_vs_league_avg', 'Performance_Grade_vs_league_avg', 'Current_Overall_vs_league_avg', 'Future_Overall_vs_league_avg', 'Experience_vs_league_avg', 'Pedigree_Percentage_vs_league_avg'],  # Target the "Diff" column
        palette=["#FF0000", "#FFFF00", "#00FF00"],  # Red to green gradient
        domain=None  # Automatically inferred from data
    )
    .data_color(
        columns=['PenaltiesCommitted_vs_league_avg'],
        palette=["#FF0000", "#FFFF00", "#00FF00"],  # Red to green gradient,
        domain=None,
        reverse=True
    )
    .tab_style(
        style=[
            style.fill(color="#EDEDED"),
            #style.text(weight="bold")
        ],
        locations=loc.body(columns=['Intelligence', 'Performance_Grade', 'Current_Overall', 'Future_Overall', 'Experience'])) ## Does colouring and bolding actually help?
    .tab_style(
        style=[
            style.fill(color="#F7F7F7"),
        ],
        locations=loc.body(columns=['PenaltiesCommitted', 'Pedigree_Percentage'])
    )
).save(f"{output_dir}/QB_Analysis.png", selector='table', scale=2.0, expand=0, web_driver='chrome', window_size=(6000, 6000), debug_port=None, _debug_dump=None)

Description

I am getting a Javascript error when trying to save an image, I had previously been able to use the exact same script to do this around 1 month ago - this is a fresh venv so a new install of GT if that is pertinent to note. Any idea what could be causing it or how I could solve it/proceed with saving these images?

Traceback

---------------------------------------------------------------------------
JavascriptException                       Traceback (most recent call last)
Cell In[16], line 85
      1 (
      2     GT(qb)
      3     .tab_header(
      4         title=md("<img src='https://i.imgur.com/xJYzCF8.png' width='90' height='90' style='vertical-align: middle;'> &#x1F3C8; **Analysis by Position Group** &#x1F3C8; <img src='https://i.imgur.com/xJYzCF8.png' width='90' height='90' style='vertical-align: middle;'>"), ## add small footballs to the title. ## these characters cause issues when saving. 
      5         subtitle=md("_**2065 Regular Season**_")
      6     )
      7     .fmt_image(
      8         columns='Team',
      9         path=analysis_path,
     10         file_pattern="{}.png"
     11     )
     12     .cols_align(
     13         align="center", columns=None
     14     )
     15     .cols_label(
     16         Team = (" "),
     17         Position_Group = (" "),
     18         Intelligence = ("Intel"),
     19         Performance_Grade = ("Performance"),
     20         Current_Overall = ("Current"),
     21         Future_Overall = ("Future"),
     22         PenaltiesCommitted = ("Penalties"),
     23         Pedigree_Percentage = ("Pedigree"),
     24         Intelligence_vs_league_avg = ("Int"),
     25         PenaltiesCommitted_vs_league_avg = ("Pen"),
     26         Performance_Grade_vs_league_avg = ("Perf"),
     27         Current_Overall_vs_league_avg = ("Curr"),
     28         Future_Overall_vs_league_avg = ("Fut"),
     29         Experience_vs_league_avg = ("Exp"),
     30         Pedigree_Percentage_vs_league_avg = ("Pedigree")
     31     )
     32     .tab_options(
     33         container_width = "100%",
     34         heading_background_color="#990033",
     35         table_border_top_color="#990033",
     36         table_font_names="Calibri",
     37         table_font_size="20px"
     38     )
     39     .tab_style(
     40         style=style.fill(
     41             color=map_colour_analysis),
     42         locations=loc.body("Position_Group")
     43         )
     44     .tab_style(
     45         style=style.text(
     46             color=text_colour_analysis),
     47         locations=loc.body("Position_Group")
     48         )
     49     .tab_spanner(
     50         label=md('**Cumulative**'),
     51         columns=['PenaltiesCommitted', 'Pedigree_Percentage']
     52     )
     53     .tab_spanner(
     54         label=md('**Group Averages**'),
     55         columns=['Intelligence', 'Performance_Grade', 'Current_Overall', 'Future_Overall', 'Experience']
     56     )
     57     .tab_spanner(
     58         label=md('**Versus League Average**'), ### MAYBE THE ORDER HERE NEEDS TO BE CHANGED TO HAVE PENALTIES SECOND LAST LIKE THE LEFT HAND COLUMNS?
     59         columns=['Intelligence_vs_league_avg', 'Performance_Grade_vs_league_avg', 'Current_Overall_vs_league_avg', 'Future_Overall_vs_league_avg', 'Experience_vs_league_avg','PenaltiesCommitted_vs_league_avg', 'Pedigree_Percentage_vs_league_avg']
     60     )
     61     .fmt_percent(['Intelligence_vs_league_avg', 'PenaltiesCommitted_vs_league_avg', 'Performance_Grade_vs_league_avg', 'Current_Overall_vs_league_avg', 'Future_Overall_vs_league_avg', 'Experience_vs_league_avg', 'Pedigree_Percentage_vs_league_avg'], decimals=1, drop_trailing_zeros=True, scale_values=False)
     62     .data_color(
     63         columns=['Intelligence_vs_league_avg', 'Performance_Grade_vs_league_avg', 'Current_Overall_vs_league_avg', 'Future_Overall_vs_league_avg', 'Experience_vs_league_avg', 'Pedigree_Percentage_vs_league_avg'],  # Target the "Diff" column
     64         palette=["#FF0000", "#FFFF00", "#00FF00"],  # Red to green gradient
     65         domain=None  # Automatically inferred from data
     66     )
     67     .data_color(
     68         columns=['PenaltiesCommitted_vs_league_avg'],
     69         palette=["#FF0000", "#FFFF00", "#00FF00"],  # Red to green gradient,
     70         domain=None,
     71         reverse=True
     72     )
     73     .tab_style(
     74         style=[
     75             style.fill(color="#EDEDED"),
     76             #style.text(weight="bold")
     77         ],
     78         locations=loc.body(columns=['Intelligence', 'Performance_Grade', 'Current_Overall', 'Future_Overall', 'Experience'])) ## Does colouring and bolding actually help?
     79     .tab_style(
     80         style=[
     81             style.fill(color="#F7F7F7"),
     82         ],
     83         locations=loc.body(columns=['PenaltiesCommitted', 'Pedigree_Percentage'])
     84     )
---> 85 ).save(f"{output_dir}/QB_Analysis.png", selector='table', scale=2.0, expand=0, web_driver='chrome', window_size=(6000, 6000), debug_port=None, _debug_dump=None)

File d:\Python_Projects\FOF_CSV_PRACTICE\FOF_PENALTIES\.venv\Lib\site-packages\great_tables\_export.py:458, in save(self, file, selector, scale, expand, web_driver, window_size, debug_port, encoding, _debug_dump)
    455     encoded = base64.b64encode(html_content.encode(encoding=encoding)).decode(encoding=encoding)
    456     headless_browser.get(f"data:text/html;base64,{encoded}")
--> 458     _save_screenshot(headless_browser, scale, file, debug=_debug_dump)
    460 if debug_port and web_driver not in {"chrome", "firefox"}:
    461     warnings.warn("debug_port argument only supported on chrome and firefox")

File d:\Python_Projects\FOF_CSV_PRACTICE\FOF_PENALTIES\.venv\Lib\site-packages\great_tables\_export.py:498, in _save_screenshot(driver, scale, path, debug)
    495 original_size = driver.get_window_size()
    497 # set table zoom ----
--> 498 driver.execute_script(
    499     "var el = document.getElementsByTagName('table')[0]; "
    500     f"el.style.zoom = '{scale}'; "
    501     "el.parentNode.style.display='none'; "
    502     "el.parentNode.style.display='';"
    503 )
    505 if debug == "zoom":
    506     return _dump_debug_screenshot(driver, path)

File d:\Python_Projects\FOF_CSV_PRACTICE\FOF_PENALTIES\.venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py:528, in WebDriver.execute_script(self, script, *args)
    525 converted_args = list(args)
    526 command = Command.W3C_EXECUTE_SCRIPT
--> 528 return self.execute(command, {"script": script, "args": converted_args})["value"]

File d:\Python_Projects\FOF_CSV_PRACTICE\FOF_PENALTIES\.venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py:429, in WebDriver.execute(self, driver_command, params)
    427 response = self.command_executor.execute(driver_command, params)
    428 if response:
--> 429     self.error_handler.check_response(response)
    430     response["value"] = self._unwrap_value(response.get("value", None))
    431     return response

File d:\Python_Projects\FOF_CSV_PRACTICE\FOF_PENALTIES\.venv\Lib\site-packages\selenium\webdriver\remote\errorhandler.py:232, in ErrorHandler.check_response(self, response)
    230         alert_text = value["alert"].get("text")
    231     raise exception_class(message, screen, stacktrace, alert_text)  # type: ignore[call-arg]  # mypy is not smart enough here
--> 232 raise exception_class(message, screen, stacktrace)

JavascriptException: Message: javascript error: Cannot read properties of undefined (reading 'style')
  (Session info: chrome=132.0.6834.160)
Stacktrace:
	GetHandleVerifier [0x00007FF7937302F5+28725]
	(No symbol) [0x00007FF793692AE0]
	(No symbol) [0x00007FF79352510A]
	(No symbol) [0x00007FF79352BD70]
	(No symbol) [0x00007FF79352EDF8]
	(No symbol) [0x00007FF7935C1460]
	(No symbol) [0x00007FF79359FFAA]
	(No symbol) [0x00007FF7935C0181]
	(No symbol) [0x00007FF79359FD53]
	(No symbol) [0x00007FF79356A0E3]
	(No symbol) [0x00007FF79356B471]
	GetHandleVerifier [0x00007FF793A5F30D+3366989]
	GetHandleVerifier [0x00007FF793A712F0+3440688]
	GetHandleVerifier [0x00007FF793A678FD+3401277]
	GetHandleVerifier [0x00007FF7937FAAAB+858091]
	(No symbol) [0x00007FF79369E74F]
	(No symbol) [0x00007FF79369A304]
	(No symbol) [0x00007FF79369A49D]
	(No symbol) [0x00007FF793688B69]
	BaseThreadInitThunk [0x00007FF81CFF7374+20]
	RtlUserThreadStart [0x00007FF81E51CC91+33]
@HansMellman
Copy link
Author

I've rolled back to version 0.11.0 as that is the version I had working in another project - I can confirm that this error does not occur when attempting to run the same file with that previous version installed.

@HansMellman
Copy link
Author

I am also now getting strange behaviour where it adds palatial whitespace to the underneath of my table - though it only seems to be doing it inconsistently - for certain dataframes (despite the formatting remaining identical as per the code above, just the dataframe input changing. As per the two images below:

Correct image:

Image

Incorrect image rendered with too much white space at the end:

Image
Though it's a little hard to tell from the white on white background here on github, this text is directly under the image for clarity.

@josephbenjamin
Copy link

josephbenjamin commented Feb 7, 2025

I can confirm that I am also having this exact same issue. Unfortunately, this is my first time implementing Great Tables in my workflow, and I must say that it has been a battle with the GT.save() function so far. I have eventually managed to get the save working, but I have two outstanding issues:
- rendering of "€" symbol (which appears fine when opening the raw html in chrome, but not when using the GT.save()
- whitespace rendering below the table as per this thread.

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

No branches or pull requests

2 participants