2

I am producing a HTML report output using R and when i get the output html file and open it I can see the charts i created using ggplot no problem but if i send the html file to anyone else the charts are missing and they only see the text. My code is below, any advice on what I am missing would be great.

Also i have an image from my local drive that isn't showing up.

---
title: "title"
 ``author: 
- "X"
date: "`r format(Sys.time(), '%d %B %Y')`"
output: 
  html_document: 
 number_sections: yes
toc: yes
runtime: shiny    
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,message=FALSE, warning=FALSE)
```

{r libraries, include=FALSE} library(plyr) library(dplyr) library(tidyverse) library(ggplot2) library(forcats) library(reshape) library(png)

```{r, fig.width=12, fig.height=6, fig.align="center"}
# read in data file
lj= read.csv("LJ_Final.csv")  # read csv file

#rename variables to fit charts
names(lj)[names(lj) == "2015"] <- "15"

myvars <- c("HB","15")
newdatajoiner <- lj[myvars]

newdatajoiners.long<-melt(newdatajoiner,id.vars="HB")

aggdatajoiners <-aggregate(value ~ HB + variable, data = 
newdatajoiners.long, sum)

#plot the data
aggdatajoiners%>%
ggplot(aes(x=variable,y=value,fill=factor(HB)))+
 geom_bar(stat="identity",position="dodge")+
 labs(x="", y="")+
 theme_bw()+
 facet_wrap(~HB)
```
```{r,fig.align="center",out.width = "3000px"}
knitr::include_graphics('./tablefife.png')
```

2 Answers 2

1

@user3018495 The other thread describes how to exclude the charts. To include the charts in the output HTML document, one sets self_contained to yes rather than no in the Rmd output options.

---
title: "your title goes here"
output:
   html_document:
   self_contained: yes
   toc: yes
   toc_float: yes
---

If you are using RStudio with knitr, this is configured in RStudio options. First select the gear in the code editor window.

enter image description here

Next, select the Advanced tab, and

  1. click Standalone HTML
  2. then press `OK'.

enter image description here

When you knit the document the resulting HTML file will contain the charts, as illustrated by a test HTML document that I posted in a Github repository so it can be viewed by the Github HTML Previewer.

regards,

Len

Sign up to request clarification or add additional context in comments.

Comments

1

When your HTML is generated from the Markdown file an image folder is generated with the HTML, your images are referenced by the HTML, not included in the html file itself, You need to send this folder as well.

You could convert the image to a base64 string and embed in the html file, however I don't know how to do that automatically in R

4 Comments

This was solved on this other thread: stackoverflow.com/questions/14870589/…
Does that mean there's no way of including images in a HTML Output using markdown?
There is, if you are using the command line you need to use the base64 parameter like in the link above, if you ate using RStudio, click on the gear next to Knit, Output Options, Advanced and check "Create a standalone HTML document", images should now be embeded as a base64 url
The images show up for me when I run it but if I share the html file, the charts from the code above don't show up. Even when I have create stand alone ticked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.