Trouble converting to epub using bookdown

Hi all

(Previously posted in stack exchange 4 days ago, with no replies.)

I am trying to create an epub version of a book that successfully compiles into PDF and HTML.

It seems that using kable_styling is causing the issue.

Consider the code from here exactly as it stands:

options(kableExtra.html.bsTable = T) iris[1:10, ] %>%   
mutate_if(is.numeric, function(x) {
    cell_spec(x, bold = T, 
              color = spec_color(x, end = 0.9),
              font_size = spec_font_size(x))   }) %>%   
mutate(Species = cell_spec(
    Species, color = "white", bold = T,
    background = spec_color(1:10, end = 0.9, 
                            option = "A", direction = -1)   )) %>%   
kable(escape = F, align = "c", booktabs = T) %>%   
kable_styling(c("striped", "condensed"), 
                latex_options = "striped", 
                full_width = F)

Running this code generates the error message:

Error: Functions that produce HTML output found in document targeting epub3 output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

always_allow_html: true

Note however that the HTML output will not be visible in non-HTML formats.

If I remove the kable_styling command, all works well: no error at all.

Fiddling and trouble-shooting my own code suggests the same: the problem is with kable_styling.

Am I doing something wrong, or is there a problem (and, hopefully, a fix)?

Thanks.

P.

It is possibly an issue with the kableExtra package. I would look this way.

Here is a resource among others: Using kableExtra in Bookdown

@haozhu233 If I may ping you. You may have the answer if this is possible or not, and about limitation with EPUB and bookdown.

If we can improve / revisit something please tell us.

Seems not so easy to use HTML deps inside EPUB document though... :thinking:

Hi @cderv, yeah, I think your interpretation is correct. As I pointed out in that rmarkdown issue, rmarkdown::paged_table couldn't load its dependencies as well... I'm not so familiar with how epub handles html styles but it seems to be very limited.

An alternative way is to generate tables as images so it no longer depends on the rendering platforms.

Thanks for confirming.

I'll have a look at that some days. The solution to use image for EPUB for HTML table seems the better one as of now! :+1:

I've been doing this, which is not ideal but usually (but not always) sufficient:

if( knitr::is_latex_output() ) {
   code_To_Produce_Table_latex %>%
   kable_styling(...) %>%
   row_spec(...)
}
if( knitr::is_html_output() ) {
   out <- code_To_Produce_Table_html

   if ( knitr::is_html_output(excludes = "epub")) {
     kable_styline(out,  ...) %>%
     row_spec(...)
   } else {
    out
   }
}

But thanks. Be nice if epub output was compatible though.

P.

1 Like