A co-worker of mine showed me a cool way to use Rstudio and turn a markdown R script into an hmtl. All the plots from the Rscript are embedded in the html, so the one html file can be shared and contain the full documentation in one file. I am trying to duplicate this outside of the Rstudio GUI, so that the html is automatically created (not by a user with a GUI). I have tried knit() and knit2html(), these create html files for me, but they also create a "figure" folder that I would have to pass around with the html. How can I embed plots and all into a single html file.
Asked
Active
Viewed 1,465 times
0
-
Is there a `hello-random.png` file in the figure directory? Is a file `test.md` created? `test.html`? I don't know what could cause a "couldn't connect to host" error (first guess is the `browseURL` call which just starts a viewer) but it works for me. – Brian Diggs Mar 21 '13 at 02:50
-
I apologize. I thought I had tried everything, but in restarting R and trying again it worked for me as well. I must have messed up some option in knitr while trying a bunch of different things. – Alex Bettinardi Mar 21 '13 at 14:47
1 Answers
1
Clicking Knit HTML
in RStudio is (supposed to be) equivalent to knit2html()
in knitr
. You will indeed see a figure
directory, but you can safely ignore it -- all your plots have been embedded in the HTML file by default. When you share the HTML file with your co-workers, you only need to pass the HTML file to them. To verify this, simply delete the figure
directory and see if the plots are still in the HTML file.
Update on 2020/04/20: Please ignore the answer above. RStudio no longer calls knitr::knit2html()
. See this post for an update: https://stackoverflow.com/a/10654295/559676

Yihui Xie
- 28,913
- 23
- 193
- 419
-
I apologize for asking such a simple question - I was trying so many things yesterday, I missed that obvious answer. A follow up if possible. My xtable tables are displaying with leading comment values and surrounded by a "code" box - I wish I could insert a screen shoot it would be easier to describe. If I use knit() I just get the leading "##", but if I use knit2html() I get the leading "##" and the html tables are given a different format and surrounded by a "code box" (best way I can describe it without a picture). Would it be best to post this as a new question - I am new to this site – Alex Bettinardi Mar 21 '13 at 19:34
-
Any help about my formatting question would be great, but after playing around a little bit, I bet it is because I started off trying to write in Rhtml using knit() and I am guessing that knit2html() is looking for an Rmd, with different formatting. So it is probably some issue with my formatting. – Alex Bettinardi Mar 21 '13 at 19:47
-
@Yihui knit2html() seems not in use any more. I was wondering if you could consider my question here https://stackoverflow.com/questions/61315190/how-can-i-knit-a-rmarkdown-file-into-a-html-file-which-embeds-plots. Thanks. – Tim Apr 20 '20 at 10:35
-
@Tim You are right. Please see https://stackoverflow.com/a/10654295/559676 for an update. Thank you! – Yihui Xie Apr 20 '20 at 15:30