Reputation: 151
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')
```
Upvotes: 2
Views: 7486
Reputation: 10875
@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.
Next, select the Advanced
tab, and
Standalone HTML
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
Upvotes: 1
Reputation: 108
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
Upvotes: 1