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

webshot2 does not allow transparent tables. #227

Closed
padpadpadpad opened this issue Jul 28, 2020 · 9 comments
Closed

webshot2 does not allow transparent tables. #227

padpadpadpad opened this issue Jul 28, 2020 · 9 comments

Comments

@padpadpadpad
Copy link

Using flexible 0.5.10, when trying to save out a table that uses webshot2 (for bold rendering), the transparent argument does not work.

table <- data.frame(x = c(1:3), y = c(1:3)) %>%
flextable() %>%
bold(part = 'all') %>%
bg(part = 'all', bg = 'transparent')

save_as_image(table, 'table.png', webshot = 'webshot2')
@davidgohel

This comment has been minimized.

@davidgohel davidgohel reopened this Aug 25, 2020
@davidgohel
Copy link
Owner

davidgohel commented Aug 25, 2020

I don't really know how to fix that. Table cells are transparent. I think the white is coming from the body background of the web page that is considered as white by chrome (via webshot2).

When webshot is used, it's ok, but not when webshot2 is used.

@atusy
Copy link

atusy commented Aug 25, 2020

I guess there are nothing we can do within flextable.

The following link infers --default-background-color=0 is required.
https://bugs.chromium.org/p/chromium/issues/detail?id=689349

However, I guess webshot2 package does not have feature to specify it.

I also challenged modify the chromote package to include--default-background-color=0 by default.
https://github.com/rstudio/chromote/blob/b706e2186bab6a25b8d28935a70e7383f3afb6c2/R/chrome.R#L54
However, it conflicts with --remote-debugging-port=0.
Even if I remove --remote-debugging-port=0, I get the following error and I have no idea to fix it.

Error in launch_chrome(path, args) :
Failed to start chrome. Error: [0826/002005.878925:ERROR:viz_main_impl.cc(161)] Exiting GPU process due to errors during initialization
[0826/002006.007961:ERROR:gpu_channel_manager.cc(459)] ContextResult::kFatalFailure: Failed to create shared context for virtualization.

@wch Do you have any ideas?

@wch
Copy link

wch commented Aug 25, 2020

According to this, the background color probably needs to be set via the Chrome Devtools Protocol.
https://bugs.chromium.org/p/chromium/issues/detail?id=689349#c20

If you want to see if it actually works, I suggest trying first by issuing commands with Chromote. Then if that works, the changes could be brought into webshot2.

@atusy
Copy link

atusy commented Aug 25, 2020

@wch Thanks for the comments! I'll try later.

@davidgohel
Copy link
Owner

I can confirm, this command is producing a transparent image (and if no --default-background-color=0, background is white):

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --screenshot="filename.png" --default-background-color=0 --crash-dumps-dir=tmp "http://127.0.0.1:4321/table.html"

filename

@atusy
Copy link

atusy commented Aug 26, 2020

Great! I'm suffering some issues with using headless chrome on Docker...
It may take some time for me to contribute.

@davidgohel
Copy link
Owner

  • webshot2 does not allow transparent background.
  • webshot does allow transparent background.

This can't be fixed from flextable.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants