Add local image file to presentation R

I am trying to include a single image file ( .png ) using R markdown for presentation R. I made the following sentence: How to import a local image using knitr for markdown but using ![title](my.png) , I get this error:

Error: unexpectedly '[' in "! ["

The my.png file is in the current path. I also tried using the absolute path, but got the same error message.

Too high a value inside r of the cartridge also failed.

I also tried

 ```{r,fig.width=350, fig.height=250,echo=FALSE} library(png) library(grid) appimg <- readPNG('my.png') grid.raster(appimg) ``` 

but also failed!

I am working on windows 7 R studio 0.98.1102 and R 3.2.1.

+4
source share
3 answers

After a huge google search. I will finally find out what the problem is.

The key is that HTML cannot reference the local file for security reasons. Besides being a local HTML file, it can reference a local file in the same file directory.

And the presentation of R is actually an HTML file, such as a web page.

So, just put your image file in the same directory with the HTML file, everything will work. At least it worked for me.

Just use

![some caption](img_file_name.png)

+9
source

Removing quotes that really worked for me, and note that it’s better not to keep spaces by naming the image as being used,

 ![title](my_image.png) 

Using quotes or spaces (when renaming) in this case did not work.

+5
source

If your output format is: slidy_presentation you can use the html code:

<img src="/Users/name/folder/xyz.png";>

In addition, if you want to align and adjust the image to a certain side (say to the right of your final output and specify the size), you can use something like

<img src="/Users/name/folder/xyz.png"; style="max-width:280px;float:right;">

0
source

All Articles