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')
```
#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
click Standalone HTML
then press `OK'.
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
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
Related
The output from the knitted HTML from R markdown does show the paged table but does not on github when I preview it through htmlpreview.github.io.
Something I noticed was that the .html code was different when opened through chrome and vs. The vs code matches the inspect elements on github
Code from R markdown (``` changed to ``'):
---
output:
html_document:
df_print: paged
editor_options:
chunk_output_type: inline
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
``'
```{r }
library(rmarkdown)
paged_table(Apr22, options = list(max.print = 5))
```
Local Chrome Inspect
Online Github Inspect
I am trying to compile various plots in an R markdown file. I would prefer that the HTML output produced images using scalable vector graphics instead of the default PNG images. Currently, I am using the following method to achieve this:
---
title: "SVG Plot Test"
output:
html_document:
df_print: paged
---
```{r setup-chunk}
knitr::opts_chunk$set(dev = "svg")
```
```{r test_plot}
library(ggplot2)
ggplot(airquality, aes(x = Temp, y = Wind)) +
geom_point()
```
However, when I knit these chunks to HTML, an additional folder is created and the plot is saved within that folder as well. With the large number of plots I am creating, I'd prefer not to save these copies as well, since they are already present within the resulting HTML document.
How can I prevent these additional files from being created while still getting svg output in the HTML file?
Showing the code in PDF can be long and distracting to some readers or clients, but I would leave it as an option in the HTML version if they want to reproduce it or verify what I've done. Depending on whom I work with, I may share one or the other (or both), but I want to avoid changing the Rmd script each time to produce them.
Thus, I want to be able to knit my R Markdown script to HTML and PDF in a way so that the HTML output can show the code (with code_folding in the output: html_document options), but prevent the code from appearing in my PDF output.
Is there a way to do that without recoding part of the script each time?
Take this example R Markdown text:
---
title: "Title"
output:
pdf_document:
df_print: kable
html_document:
code_folding: show
df_print: paged
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
```{r mtcars}
# I want to make this code visible when I knit to HTML, but hidden when I knit to PDF.
# How do I do that?
mtcars[1:2, 1:4]
```
It will show the mtcars chunk when it's knitted.
I can change knitr::opts_chunk$set(echo = TRUE) to knitr::opts_chunk$set(echo = FALSE) in the setup chunk to prevent the code from showing in the PDF output, but the code will disappear in the HTML output as well.
code_folding: hide can hide the code for html_document output options and allows the reader to see the code if necessary. However, code_folding: hide does not work for pdf_document output options. Is there an alternative that I can use?
Maybe use is_html_output in eval and echo
---
title: "Title"
output:
html_document:
code_folding: show
df_print: paged
pdf_document:
df_print: kable
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
```{r mtcars, eval = knitr::is_html_output(), echo = knitr::is_html_output()}
# I want to make this code visible when I knit to HTML, but hidden when I knit to PDF.
# How do I do that?
mtcars[1:2, 1:4]
```
-output html
-output pdf
I've finished a lovely R Markdown script with an HTML output and was excited to share the analysis to colleagues internally, by sharing the Sharepoint link.
The output works fine when I open the HTML file directly on my machine. But for whatever reason, when I share or view via the Sharepoint link, simple things like the TOC, plotly graphs and leaflet maps do not render.
Here's an example of the problem I'm running into, with some really basic script just as an example.
---
title: "Test_Output"
output:
html_document:
toc: true
toc_float: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
Hello, this is a test.
## Test
```{r test plotly, echo = FALSE, warning = FALSE, message = FALSE}
library(plotly)
plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
```
And so this is the output, right.
But when I share the link (something like this https://mycompany.sharepoint.com/:f:/s/mydepartment/EvLlZjmxOetc)
or if someone were to try and just navigate to the page on our Sharepoint, the output is all messed up. It looks like this: plots and TOC and maps do not render.
If anyone can help me to figure out how to allow my Markdown HTML output to render instantly once I share the link, that would be incredible, and I would feel like all my work on the script was not in vain!
I've tried adding "download=1" to the end of the URL, which indeed gives users an ability to view the output correctly by clicking the link and downloading the HTML, but this is not optimal as this is supposed to be a live product that I will continue updating.
Turns out that a solution is to rename your HTML file to aspx. Then, when you provide the link to users in your organisation, they can easily view it.
This is the first time I am using rmarkdown to knit a document into an html output. I see the output as an html document, no problem. However the output is linked to my personal working directory (example:file:///C:/Users/e337384/table_formatting.html).
---
title: "Inter-Rater Agreement (Long Beach)"
output:
html_document: default
word_document: default
date: "2/6/2020"
---
```{r,echo=FALSE, message=FALSE}
library(knitr)
require(kableExtra)
library(tidyverse)
options(knitr.table.format = "html")
```
I would like to be able to share the html document with my team, but since the output is linked to my drive only I can see it. How do I save this output in a way that allows me to share this html output?!
Recently, the export mechanism for files has changed slightly.
Now you have to check the corresponding check-box of the file you wish to export and then select More -> Export, as shown in this picture: