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:
Related
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.
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
How can I display DT::datatable objects from a rmarkdown script onto a pdf document? My code so far is breaks down with the following error:
processing file: reportCopy.Rmd
output file: reportCopy.knit.md
Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML.
Including always_allow_html: yes in the YAML header suppresses the error, but nothing appears on the pdf.
I would be grateful for any help. My code is currently:
---
title: "DT"
output: pdf_document
---
### Chart 1
```{r}
DT::datatable(head(mtcars))
```
( I don't know if it matters, but my datatables are in fact created in a shiny application. Ideally, I would have liked to have the prerendered tables simply dumped into the rmarkdown script... but I switched tactic and now try to render the tables directly in the rmarkdown code)
Since knitr v1.13, HTML widgets will be rendered automatically as screenshots taken via the webshot package.
You need to install the webshot package and PhantomJS:
install.packages("webshot")
webshot::install_phantomjs()
(see https://bookdown.org/yihui/bookdown/html-widgets.html)
You cannot usedatatable in pdf_document (datatable is interactive, pdf is static), only in html_document!
The only possibility for PDF is to use the kable or for example pandoc.table
--> if You really wanna get the look of datatable and as You said datatable is created in a shiny application, then You can have a look at the webshot package, which is going to create a screenshot of Your datatable from shiny app which You can use further in pdf as a image.
I'm trying to produce a google motion chart in R slidify. I looked up a lot of examples online and it seems some people have successfully embedded google motion chart in an R slidify slide. Then when I tried my own using similar code, it gives me blank result. I also use the same method to produce a google pie chart and it works well (a pie chart shows in the plotting area)
Here is my simplified code below (Here I am using the Fruits dataset just like all other demo) :
---
title: "Title"
author: "Me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
ioslides_presentation:
incremental: yes
transition: default
widescreen: yes
slidy_presentation:
incremental: yes
job: Job Title
license: by-nc-sa
mode: selfcontained
hitheme: tomorrow
highlighter : highlight.js
subtitle: Subtitle
framework: io2012
widgets: []
---
## GoogleVis Motion chart example
```{r motionchartcode1, results='asis', warning=FALSE, comment=NA}
library(googleVis)
options(gvis.plot.tag='chart')
M <- gvisMotionChart(Fruits, 'Fruit', 'Year',
options=list(width=400, height=350))
#plot(M)
print(M, tag = 'chart')
```
---
## GoogleVis Pie chart example
```{r motionchartcode, results='asis'}
library(googleVis)
options(gvis.plot.tag='chart')
Pie <- gvisPieChart(CityPopularity,
options=list(width=400, height=200))
print(Pie, tag = 'chart')
```
Then I used slidify("demo.Rmd") to compile it to a html file. The first slide gives no plots but a blank plotting area.
I'm not sure which part is effecting this outcome: the setup in --- part, the options in r markdown chunk or my browser environment?
Hope someone can give me ideas.
The plot command in R uses the internal R http help server to overcome this limitation.
Here's how I overcame it:
Go to
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html
Click on the dropbox which says 'Edit location' and choose 'add location'
Click 'browse for folder or browse for file'
Choose the folder (or file) in which was your saved html output
Click OK
Also you can modify your codes, for example I did:
suppressPackageStartupMessages(library(googleVis))
options(gvis.plot.tag='chart')
M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")
plot(M1)
print(M1, file="myGoogleVisChart.html")
Now open your googleVis html file and it should display successfully.
In fact, any googleVis file you open from within the folder you selected will also display as you would expect.
Please note that I am using MS Internet Explorer and it asked me to activate ActiveX before I was able to view the output from above, and it was working for me.
Still, if you can not see then also please check for :
https://cran.r-project.org/web/packages/googleVis/vignettes/googleVis.pdf
Quick Summary
How do I place HTML files in place within an R Markdown file?
Details
I have created some nice animated choropleth maps via choroplethr.
As the link demonstrates, the animated choropleths function via creating a set of PNG images, which are then rolled into an HTML file that cycles through the images, to show the animation. Works great, looks great.
But now I want to embed / incorporate these pages within the .Rmd file, so that I have a holistic report including these animated choropleths, along with other work.
It seems to me there should be an easy way to do an equivalent to
Links:
[please click here](http://this.is.where.you.will.go.html)
or
Images:
![cute cat image](http://because.that.is.what.we.need...another.cat.image.html)
The images path is precisely what I want: a reference that is "blown up" to put the information in place, instead of just as a link. How can I do this with a full HTML file instead of just an image? Is there any way?
Explanation via Example
Let's say my choropleth HTML file lives in my local path at './animations/demographics.html', and I have an R Markdown file like:
---
title: 'Looking at the demographics issue'
author: "Mike"
date: "April 9th, 2016"
output:
html_document:
number_sections: no
toc: yes
toc_depth: 2
fontsize: 12pt
---
# Introduction
Here is some interesting stuff that I want to talk about. But first, let's review those earlier demographic maps we'd seen.
!![demographics map]('./animations/demographics.html')
where I have assumed / pretended that !! is the antecedent that will do precisely what I want: allow me to embed that HTML file in-line with the rest of the report.
Updates
Two updates. Most recently, I still could not get things to work, so I pushed it all up to a GitHub repository, in case anyone is willing to help me sort out the problem. Further details can be found at that repo's Readme file.
It seems that being able to embed HTML into an R Markdown file would be incredibly useful, so I keep trying to sort it out.
(Older comments)
As per some of the helpful suggestions, I tried and failed the following in the R Markdown file:
Shiny method:
```{r showChoro1}
shiny::includeHTML("./animations/demographics.html")
```
(I also added runtime:Shiny up in the YAML portion.)
htmltools method:
```{r showChoro1}
htmltools::includeHTML("./animations/demographics.html")
```
(In this case, I made no changes to the YAML.)
In the former case (Shiny), it did not work at all. In fact, including the HTML seemed to muck up the functionality of the document altogether, such that the runtime seemed perpetually not-fully-functional. (In short, while it appeared to load everything, the "loading" spindel never went away.)
In the latter case, nothing else got messed up, but it was a broken image. Strangely, there was a "choropleth player" ribbon at the top of the document which would work, it's just that none of the images would pop up.
For my own sanity, I also provided simple links, which worked fine.
[This link](./animations/demographics.html) worked without a problem, except that it is not embedded, as I would prefer.
So it is clearly a challenge with the embedding.
Here is a hack (probably inelegant)...idea is to directly insert HTML programmatically in Rmd and then render Rmd.
temp.Rmd file:
---
title: "Introduction"
author: "chinsoon12"
date: "April 10, 2016"
output: html_document
---
<<insertHTML:[test.html]
etc, etc, etc
```{r, echo=FALSE}
htmltools::includeHTML("test.html")
```
etc, etc, etc
test.html file:
<html>
<head>
<title>Title</title>
</head>
<body>
<p>This is an R HTML document. When you click the <b>Knit HTML</b> button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:</p>
<p>test test</p>
</body>
</html>
verbose code to replace Rmd code with HTML code and then render (can probably be shortened by a lot)
library(stringi)
subHtmlRender <- function(mdfile, htmlfile) {
#replace <<insertHTML:htmlfile with actual html code
#but without beginning white space
lines <- readLines(mdfile)
toSubcode <- paste0("<<insertHTML:[",htmlfile,"]")
location <- which(stri_detect_fixed(lines, toSubcode) )
htmllines <- stri_trim(readLines(htmlfile))
#render html doc
newRmdfile <- tempfile("temp", getwd(), ".Rmd")
newlines <- c(lines[1:(location-1)],
htmllines,
lines[min(location+1, length(lines)):length(lines)]) #be careful when insertHTML being last line in .Rmd file
write(newlines, newRmdfile)
rmarkdown::render(newRmdfile, "html_document")
shell(gsub(".Rmd",".html",basename(newRmdfile),fixed=T))
} #end subHtmlRender
subHtmlRender("temp.Rmd", "test.html")
EDIT: htmltools::includeHTML also works with the sample files that I provided. Is it because your particular html does not like UTF8-encoding?
EDIT: taking #MikeWilliamson comments into feedback
I tried the following
copied and pasted animated_choropleth.html into a blank .Rmd
remove references to cloudfare.com as I had access issues while
rendering (see below)
knit HTML
put back those cloudfare weblinks
put the graphs in the same folder as the rendered html
open the HTML
I appear to get back the html but am not sure if the result is what you expect
Are you also facing the same issue in pt 2? You might want to post the error message and ask for fixes :). This was my error message
pandoc.exe: Failed to retrieve http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css
FailedConnectionException2 "cdnjs.cloudflare.com" 80 False getAddrInfo: does not exist (error 11001)
Error: pandoc document conversion failed with error 61
Did you try the includes: option in your YAML header?
https://rmarkdown.rstudio.com/html_document_format.html#includes
But maybe you'll have the same problem I have: I'd like to include the HTML file in a specific section in my RMarkdown document, not in the header or before/after body.
can try put this line in the Rmarkdown and then knit.
(YAML header "output: html_document"; if "runtime: shiny" somehow it does not work)