haozhu233 / kableExtra

Construct Complex Table with knitr::kable() + pipe.
https://haozhu233.github.io/kableExtra/
Other
688 stars 147 forks source link

version 1.4.0 of kableExtra, save_kable() does not export the pdf as formatted in html #830

Open irispant opened 6 months ago

irispant commented 6 months ago

Description The output of the function save_kable() of package versions 1.3.4 and 1.4.0, differs.

More specifically, the function save_kable() of package version 1.3.4 works as expected. It extracts the HTML (refer to the left image) and PDF (refer to the right image) in the correct format. export_1 3 4

However, the same function of the package version 1.4.0, does not work as expected. After installing the recommended package webshot2 with its dependencies, the function extracts the HTML (refer to the left image) in the correct format, but the PDF (refer to the right image) is not extracted as expected. export_1 4 0 \ \ In addition, it was noted that the exported info messages of the function save_kable(), differ between the two versions: kableExtra version: 1.3.4 save_kable_1 3 4

kableExtra version: 1.4.0 save_kable_1 4 0 \ \ To Reproduce

Please try to reproduce the below code, using versions 1.3.4 and 1.4.0 of the package kableExtra, and inspect the pdf outputs.

iris_df <- iris[(48:52), ] 

rownames(iris_df) <- NULL

pdf_df <- knitr::kable(iris_df, caption = "Iris Dataset", align = "ccccr") |> 
  kableExtra::kable_paper() |> 
  kableExtra::column_spec(5, bold = TRUE, border_right = TRUE, background ="#F2EFC8") |> 
  kableExtra::kable_styling(bootstrap_options = "basic", full_width = FALSE, position = "center", font_size = 20) |> 
  kableExtra::kable_classic(full_width = FALSE, html_font = "Cambria") |> 
  kableExtra::pack_rows(group_label = "setosa species", start_row = 1, end_row = 3, underline = TRUE) |> 
  kableExtra::pack_rows(group_label = "versicolor species", start_row = 4, end_row = 5, underline = TRUE) |> 
  kableExtra::footnote(general = "The end") 

kableExtra::save_kable(pdf_df, "iris_df.pdf")
haozhu233 commented 6 months ago

1.4 is using webshot2 while 1.3.4 is using webshot. https://github.com/haozhu233/kableExtra/commit/f4b8f2430e4803a573ee023293f063e04d7e74e2

Technically webshot or phantom.js is deprecated but I find it sometimes works better than other tools. Maybe we should let user select the backend instead of set it for them.

Jordanadriscoll commented 5 months ago

Just thought I would join in with my experience in the case that it may prove helpful.

I had a recent issue that appears somewhat related to @irispant's issue with version 1.4.0. I did a mass, multiple package update for my local instance of R on my windows machine and suddenly my save_kable sections were erroring and causing my script to halt. I started playing musical chairs with the packages to try to determine which package update caused this upset. I originally thought the issue was related to the ‘magick’ package and I would receive blank output png files when I didn’t have magick installed (similar to @irispant's post of their output version comparison). I would get my png files with blank output and received this message (I have obfuscated my work username in the filepaths):

image

After re-installing magick, the png files wouldn’t write any longer and I would receive this message: image

So the image would get written to .html file, but it seems then that there would be an issue locating the file to create the respective png file. I did revert back to the previous version of magick I had before my multiple package update but didn't luck out. However, when I regressed back to version 1.3.4 of kableExtra, my script started behaving as expected. Perhaps the update to version 1.4.0 doesn’t play nice with magick and/or webshot2 now?