dataframe_image icon indicating copy to clipboard operation
dataframe_image copied to clipboard

Generalize async behavior to handle styling

Open thatperson42 opened this issue 9 months ago • 1 comments

Within a Jupyter Notebook and a dataframe df, the following works properly:

import dataframe_image as dfi

df.dfi.export('filepath.png')

but the following does not work:

import dataframe_image as dfi

dfi.export(df, 'filepath.png')

It gives the error Error: It looks like you are using Playwright Sync API inside the asyncio loop. Please use the Async API instead.

For this example I can make the code change, however if I try using a Styler object df_styled = df.style, then neither of these work because AttributeError: 'Styler' object has no attribute 'dfi'.

If the dfi.export call were updated to handle the async behavior in Jupyter, then this should address this problem.

thatperson42 avatar Feb 11 '25 23:02 thatperson42

This is a bug in current version since I forgot change the default table_conversion of pandas extension from 'chrome' to 'playwright'.

You should only use table_conversion chrome in the following 2 scenarios:

  1. Your dataframe is less than 25 rows
  2. You installed chrome-shell-headless and set chrome_path to it.

To use dataframe in Jupyter:

await dfi.export_async(df, 'filepath.png')

This change is disscussed at https://github.com/dexplo/dataframe_image/issues/124

PaleNeutron avatar Feb 12 '25 12:02 PaleNeutron