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

Changing the behavior of webshot() if rendering with knit2wp() #1891

Closed
3 tasks done
JanaJarecki opened this issue Aug 26, 2020 · 2 comments
Closed
3 tasks done

Changing the behavior of webshot() if rendering with knit2wp() #1891

JanaJarecki opened this issue Aug 26, 2020 · 2 comments
Labels
feature Feature requests

Comments

@JanaJarecki
Copy link

JanaJarecki commented Aug 26, 2020

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Issue

When rendering with kit2wp() (and also in the Yaml header using output: github_document) the webshot package makes an image out of a dynamic HTML table, whereas the table works just fine with outputting to a html_document.

Minimal Working Example

Create a sample codebook

    library(codebook)       
    library(knitr)                                                             
    new_codebook_rmd() 

Change two chunks of the auto-generated file codebook.Rmd

First Chunk Change:

    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(
      warning = FALSE, # show warnings during codebook generation
      message = FALSE, # show messages during codebook generation
      error = FALSE, # do not interrupt codebook generation in case of errors,
                    # usually better for debugging
      echo = FALSE  # show R code
    )

#### Last Chunk Change
    ```{r codebook}
     compact_codebook(codebook_data)
    ```

Now render the rmd to Wordpress and compare to the normally-rendered HTML output

    # Note need to define Wordpress credentials first
     knitr::knit2wp("codebook.rmd", title = "a test post")

The issue is that in webshot() the table is rendered as image, as pointed out by Ruben Arslan: rubenarslan/codebook#55

Is there anything you can do to avoid this issue?

xfun::session_info('knitr')

r$> xfun::session_info('knitr')                                                          
R version 4.0.2 (2020-06-22)                                                             
Platform: x86_64-w64-mingw32/x64 (64-bit)                                                
Running under: Windows 10 x64 (build 18363)                                              
                                                                                         
Locale:                                                                                  
  LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252                   
  LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C                                       
  LC_TIME=German_Switzerland.1252                                                        
                                                                                         
Package version:                                                                         
  evaluate_0.14   glue_1.4.1      graphics_4.0.2  grDevices_4.0.2 highr_0.8              
  knitr_1.29      magrittr_1.5    markdown_1.1    methods_4.0.2   mime_0.9               
  stats_4.0.2     stringi_1.4.6   stringr_1.4.0   tools_4.0.2     utils_4.0.2            
  xfun_0.16       yaml_2.2.1    
@yihui
Copy link
Owner

yihui commented Sep 21, 2020

Changing knitr's behavior to generate HTML instead of a static image for the table is easy on my side, but the actual problem is that you'll have to make sure you load the correct JS libraries and CSS for the table on the WordPress site (usually in ```). That can be very tricky if you want to do it really well. We have done it in the rmarkdown package, and it's a little complicated.

Perhaps you are aware of it, but blogdown does support HTML widgets. Since knit2wp() relies on packages that are no longer actively maintained, I'd suggest you consider blogdown: #1866 (comment)

@cderv cderv added the feature Feature requests label Jan 29, 2021
@yihui yihui closed this as completed Aug 31, 2023
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests
Projects
None yet
Development

No branches or pull requests

3 participants