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

chrome_print() landscape = T not resizing HTML Widget on print? #325

Open
andrew-fuller opened this issue May 14, 2024 · 1 comment
Open

Comments

@andrew-fuller
Copy link

andrew-fuller commented May 14, 2024

Hello.

I am creating a report in my R Shiny app that sends parameters to knit a html file and then runs chrome_print() on that to convert it to a PDF. The reason it is done this way is because I want to send my echarts4r widgets as parameters to save compute time and maintain SVG lossless quality.

The issue I am having is that when I set landscape = T it does not seem to adjust the widget to the width of the print area. It does print to the correct width when performing the operation manually through a non headless browser.

Here is a minimal example below:

R Markdown

---
title: "Untitled"
author: "fullera"
date: "`r Sys.Date()`"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
Output the plot

mtcars |>
  e_charts(cyl,renderer = 'svg') |>
  e_line(mpg) |> e_animation(show = F)

R Code

library(echarts4r)
library(pagedown)


pagedown::chrome_print(input = 'untitled.html', output = 'foo.pdf', options = list(landscape=T))
@andrew-fuller andrew-fuller changed the title chrome_print() landscape = T not resizing HTML on print? chrome_print() landscape = T not resizing HTML Widget on print? May 14, 2024
@cderv
Copy link
Collaborator

cderv commented Aug 26, 2024

This is probably a problem of configuration in the websockets calls we do to chrome using the API.

Could you find time to try play with chromote and see if you have better change of finding which settings are working ? https://rstudio.github.io/chromote/

You could also see other options in chrome_print that can be set: https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF

We could then adapt what we do in pagedown accordingly.

Though, this is a complex problem of sizing before screenshoting, and it seems browser does it better. We need to find the right way to do it. I have no clue as of now.

HTML Widgets and chrome remote are hard to sync. Any help appreciated on this.

Also your example is not reproducible. It lacks proper formatting, and missing required package name. Can you update ?

Thank you !

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

No branches or pull requests

2 participants