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

Problem with rendering flextable when using equations in pagedown #332

Closed
sylvaine31 opened this issue Oct 3, 2024 · 11 comments · Fixed by #333
Closed

Problem with rendering flextable when using equations in pagedown #332

sylvaine31 opened this issue Oct 3, 2024 · 11 comments · Fixed by #333
Labels
bug an unexpected problem or unintended behavior external concerns external libraries

Comments

@sylvaine31
Copy link

sylvaine31 commented Oct 3, 2024

Hi,
I'm not sure wheter it is a flextable or a pagedown issue.
When using equations in a pagedown::html_paged Rmd, flextable does not render.
my reprex :

---
title: "Blabla"
author: "ploupi"
date: "`r format(Sys.time(), '%d %B %Y')`"
output: pagedown::html_paged
---

# mtcars with flextable does not render

```{r echo=TRUE}

ploup <- mtcars |> 
  head() |> 
  dplyr::select(mpg, cyl)

  flextable::flextable(ploup) |> 
    flextable::autofit()

```

# mtcars with print renders

``` {r echo=TRUE}

print(ploup)

```

# the equation
$$
Y = \frac{a_{x}-b} {c}
$$

If I replace the equation by a R chunk , the flextable renders without problem :

 ```{r equation1, echo = FALSE}

equatags::transform_mathjax("Y = \\frac{a_{x}-b} {c}") |> 
  htmltools::HTML()
 ```
@cderv
Copy link
Collaborator

cderv commented Oct 8, 2024

👋 @sylvaine31

First, advice on formatting: Use one more backtick to wrap you rmd source. See https://yihui.org/issue/#please-format-your-issue-correctly

Then, advice on reprex: With newer R, use |> and not %>% which allows in reprex to avoid having to laod magrittr (which is missing in our example here).

Regarding the issue, it seems there are some changes in flextable that requires some adaptation in pagedown.

Using flextable 0.8.5, it works but then starting from 0.8.6 it fails with table not showing.

So I need to check with @davidgohel what are the changes between these version. Repo has not tagged version so not easy to compare the change, but I'll do a bit of archeology.

@cderv cderv added bug an unexpected problem or unintended behavior external concerns external libraries labels Oct 8, 2024
@cderv
Copy link
Collaborator

cderv commented Oct 8, 2024

Thanks for CRAN snapshot github repo, we can access the difference in the version

Not the commit history, but it could give us some hint still

@cderv
Copy link
Collaborator

cderv commented Oct 8, 2024

It could be related to tabwid.js addition which may not run correctly with paged.js applying 🤔

@cderv
Copy link
Collaborator

cderv commented Oct 8, 2024

Possibly related to previous problem

where the fix does not work anymore

@cderv
Copy link
Collaborator

cderv commented Oct 8, 2024

And this search lead me to this commit

I think that flextable now always output shadow dom, and #216 still applies because the ft.shadow option is not existing anymore in flextable (davidgohel/flextable@439d93c#diff-f0c168982bc3b1afb5f98bd5e0230be9a96126d723db777bfde5b3dfeacf9b00L1012)

@davidgohel I'll see what I can do in pagedown but if there is a way to still not use shadow dom in paged.js context, it would be cool.

Otherwise, it will need to wait for an update in Paged.js inside pagedown but I am not sure that paged.js really support shadow dom

So we may be blocked here. 🤔

@davidgohel
Copy link

Hi @cderv

Is there a way to detect with knitr (or any option) that the format is pagedown? Something like knitr::is_html_output()?

@cderv
Copy link
Collaborator

cderv commented Oct 8, 2024

Is there a way to detect with knitr (or any option) that the format is pagedown? Something like knitr::is_html_output()?

I don't think there is yet a straightforward way. 🤔

@yihui just to confirm: Do we have a way in knitr to know which rmarkdkown format as triggered the render ?

@yihui
Copy link
Member

yihui commented Oct 9, 2024

We don't, but we can set a flag similar to

pagedown/R/paged.R

Lines 176 to 178 in 410def1

if (isTRUE(.pagedjs)) {
fmt$knitr$opts_chunk[['ft.shadow']] = FALSE
}

I feel the flag should be set in opts_knit instead of opts_chunk since it's global to the document instead of individual chunks.

With that flag (say, named is.paged.js), flextable can detect knitr::opts_knit$get('is.pagedjs').

@davidgohel
Copy link

that would be great, I could read knitr::opts_knit$get('is.pagedjs') in flextable and you could remove that fmt$knitr$opts_chunk[['ft.shadow']] = FALSE in pagedown

@cderv
Copy link
Collaborator

cderv commented Oct 10, 2024

@davidgohel you can try out #333

I have kept fmt$knitr$opts_chunk[['ft.shadow']] = FALSE for backward compatibility with older flextable

davidgohel added a commit to davidgohel/flextable that referenced this issue Oct 10, 2024
@davidgohel
Copy link

davidgohel commented Oct 10, 2024

@sylvaine31 the fix has been applied in 'flextable', you should be able to display flextables again with dev version of 'pagedown' and dev version of flextable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior external concerns external libraries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants