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

Images not rendering when I render rmarkdown at bash command line. Getting "<img..." #1592

Closed
2 tasks done
abalter opened this issue Jun 26, 2019 · 8 comments
Closed
2 tasks done
Milestone

Comments

@abalter
Copy link

abalter commented Jun 26, 2019


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/issue/.
  • [ x 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('rmarkdown'). 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('rstudio/rmarkdown').
    • 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.


When I run rmarkdown files (example attached) in RStudio and hit "save," the rendered .nb.html file contains embedded images. However when I render with Rscript -e "rmarkdown::render('file.Rmd')", I get image tags but no embedded images (or images in an output folder).

with plot
without plot

RMD File as TXT (Otherwise I'd have to escape all the stuff)
imagetest.txt

> xfun::session_info()
R version 3.5.1 (2018-07-02)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.10, RStudio 1.1.456

Locale:
  LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8    
  LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C             
  LC_ADDRESS=C           LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

Package version:
  askpass_1.1       assertthat_0.2.1  backports_1.1.4   base64enc_0.1-3   callr_3.2.0      
  cli_1.1.0         clipr_0.6.0       clisymbols_1.2.0  compiler_3.5.1    crayon_1.3.4     
  curl_3.3          desc_1.2.0        devtools_2.0.2    digest_0.6.19     evaluate_0.14    
  fs_1.3.1          gh_1.0.1          git2r_0.25.2      glue_1.3.1        graphics_3.5.1   
  grDevices_3.5.1   highr_0.8         htmltools_0.3.6   httr_1.4.0        ini_0.3.1        
  jsonlite_1.6      knitr_1.23        magrittr_1.5      markdown_1.0      memoise_1.1.0    
  methods_3.5.1     mime_0.7          openssl_1.4       pkgbuild_1.0.3    pkgload_1.0.2    
  prettyunits_1.0.2 processx_3.3.1    ps_1.3.0          purrr_0.3.2       R6_2.4.0         
  rcmdcheck_1.3.3   Rcpp_1.0.1        remotes_2.0.4     rlang_0.4.0       rmarkdown_1.13   
  rprojroot_1.3-2   rstudioapi_0.10   sessioninfo_1.1.1 stats_3.5.1       stringi_1.4.3    
  stringr_1.4.0     sys_3.2           tinytex_0.13      tools_3.5.1       usethis_1.5.0    
  utils_3.5.1       whisker_0.3.2     withr_2.1.2       xfun_0.8          xopen_1.0.0      
  yaml_2.2.0  
```

```
(base) balter@spectre:~$ lsb_release -a
LSB Version:    core-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 18.10
Release:        18.10
Codename:       cosmic
```
@yihui
Copy link
Member

yihui commented Jun 26, 2019

Otherwise I'd have to escape all the stuff

Had you followed the issue guide, you'd know how to post the example as verbatim text instead of an attachment.

The issue guide also explicitly asked for xfun::session_info('rmarkdown') instead of xfun::session_info(). Since you didn't follow this instruction precisely, I don't know your Pandoc version.

@cderv
Copy link
Collaborator

cderv commented Jun 26, 2019

To complete the previous answer, I think this has something to do with the

out.extra='1024px'

option you put in opts_chunk
what is the purpose ?

With html output, this will be added inside html <img> tag

<img src=“test_files/figure-html/unnamed-chunk-2-1.png” width=“3600” 1024px />

but 1024px alone is not a valid html option for tag img, it should be valide html and css, something like 'style="display:block;"'

I don't know if this should be considered a bug as you can provide anything into out.extra but you need to put something valid I guess. This documentation: https://yihui.name/knitr/options/

If you don't have this option, it is working fine.

@abalter
Copy link
Author

abalter commented Jun 26, 2019

@yihui Sorry about that.

> xfun::session_info('rmarkdown')
R version 3.5.1 (2018-07-02)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.10, RStudio 1.1.456

Locale:
  LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8    
  LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C             
  LC_ADDRESS=C           LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

Package version:
  base64enc_0.1.3 digest_0.6.19   evaluate_0.14   glue_1.3.1      graphics_3.5.1  grDevices_3.5.1
  highr_0.8       htmltools_0.3.6 jsonlite_1.6    knitr_1.23      magrittr_1.5    markdown_1.0   
  methods_3.5.1   mime_0.7        Rcpp_1.0.1      rmarkdown_1.13  stats_3.5.1     stringi_1.4.3  
  stringr_1.4.0   tinytex_0.13    tools_3.5.1     utils_3.5.1     xfun_0.8        yaml_2.2.0     

Pandoc version: 2.7.3

@abalter
Copy link
Author

abalter commented Jun 26, 2019

@cderv I found that option somewhere on the 'net for making my images wider in the html output. I don't think it was working anyway. So I'll take it out, or use it correctly.

Although it may not be a bug per se, it's confusing that the html renders fine from RStudio, but not at the command line.

@cderv
Copy link
Collaborator

cderv commented Jun 27, 2019

Although it may not be a bug per se, it's confusing that the html renders fine from RStudio, but not at the command line.

This is specific to the html_notebook format and its preview mode. With classic html_document format, I have this behavior when I knit from RStudio and from the command line.

I don't really know how html_notebook previewing work in RStudio - there may be something to look into in rmarkdown package, but I think it is just that in preview mode, knitr option are not used here.

If we change fig.width option in your, it does not change anything when executing chunks and previewing while clicking on the button in RStudio. Whereas, using rmarkdown::render("test.Rmd", "html_notebook") will render a .nb.html document with knitr options applied. That is why the error appear only when rendering explicitely.
In a notebook format, knitr options apply if you set them in a setup chunk. This works when you run the chunks in RStudio then click preview

---
title: "Render Plot Test"
output:
  html_notebook:
    df_print: paged
    number_sections: yes
    theme: lumen
    toc: yes
  html_document:
    df_print: paged
    toc: yes
  pdf_document:
    toc: yes
---

# Set Knitr Options
```{r setup}
library(rmarkdown)
library(knitr)

opts_chunk$set(
  echo=TRUE,
  dpi=300,
  fig.width=5
  )
```

# Plot
```{r}
plot(cars)
```

the size is changed even in preview mode with this example.
This relation between setup chunk, html_notebook and knitr options are mentioned in the Rmarkdown definitive guide.

However, no error while adding out.extra in previous example - it seems to not be used with how RStudio IDE helps preview the html_notebook. I think if this misleading behavior is related to RStudio IDE and html_notebook format previewing. I am not sure something can be fix in knitr or rmarkdown.

@kevinushey
Copy link
Contributor

kevin@cdrv:~/scratch
$ cat test.md
<img src="Untitled_files/figure-html/unnamed-chunk-1-1.png" width="1500" 1024px />
kevin@cdrv:~/scratch
$ pandoc test.md
<p>&lt;img src=“Untitled_files/figure-html/unnamed-chunk-1-1.png” width=“1500” 1024px /&gt;</p>

The problem here is that when pandoc sees the invalid HTML in the image tag, it renders it as text rather than an actual image.

@yihui yihui added this to the v1.14 milestone Jun 28, 2019
@yihui
Copy link
Member

yihui commented Jun 28, 2019

@kevinushey Thanks a lot! I think the mystery is resolved now.

@yihui yihui closed this as completed Jun 28, 2019
@github-actions
Copy link

github-actions bot commented Nov 3, 2020

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 Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants