How do I host an interactive (shiny) knitr/rmarkdown doc on GitHub Pages? - r

I have an .rmd file containing working code for a Shiny interactive knitr/rmarkdown doc. I want this doc to run via GitHub pages.
How do I do this? (Can someone walk me through the steps clearly and fully).
I understand I have to create a gh-pages branch and upload the files there. However, I don't understand what to do with my .rmd file. Do I simply just resave it as an .html file? Or does an html file have to contain something in addition to the rmd file?
Please help explain this to me -- I've spent all day trying to figure this out, but I can;t get anything to work right :(.
Prior effort: I tried following the lead given by this SO.post, but the best I can get is a screen full of block text. No formatting, code or images show up. Just the whole document's text.

Related

TOC not displaying in Blogdown post (Hugo theme Even)

I have added a new post to my site made using blogdown. Despite the presence of toc: yes in my YAML, the table of contents is not displaying on the rendered webpage. I've also tried adding:
output:
blogdown::html_page:
toc: yes
which doesn't solve the problem either. I'm currently using the Even theme (Hugo), and in the .config file, I also have toc: yes present.
I checked out this post, but I wasn't able to find the files they are referencing, nor those particular lines of code. Also my issue is with new posts, not the home page.
Does anyone know what the problem might be?
EDIT: I can see in my index.html file (generated from index.Rmd) that the code for a toc is present. For some reason, it's not being rendered on the page?
TL;DR Solution: to get the table of contents to show in the Even theme, your posts must render to the .markdown format instead of .html format. In order to make this happen, you simple use the .Rmarkdown file extension when creating the post instead of .Rmd. Now, when you use blogdown::serve_site(), your post will use the output format .markdown instead of .html. Your post will now render with a beautiful table of contents.
A note for latex math mode users: when typing in your .Rmarkdown document, you will now have to escape your $'s and \'s. So for example, $\le 0.2$
will have to be typed as \$\\le 0.2\$.
I hope this overly elaborate problem and solution is helpful to someone!
I figured out a workaround for this.
First, I'm not sure how to provide a reproducible example in this context, but I can say that if you open an RStudio project, run blogdown::new_site(theme = "olOwOlo/hugo-theme-even"), add a New Post using the Addin dropdown menu, add some headings to your post, make toc:true, use Serve Site from the Addin menu. You will see your post working fine in every respect - only it will be missing the table of contents.
Workaround:
I don't know why, but it appears that the table of contents will show if I keep a copy of the post in .md format, and delete the .html document. The default behavior seems to use the .html document if it is present; failing that, it will use the .md document.
To keep a copy of the post in .md format, use the following code in the YAML of your .Rmd document:
output:
blogdown::html_page:
keep_md: yes
Serve the site, delete the .html document (but keep the .md document), and the table of contents appears in all of its glory (you may have to actually knit the file to get the .md).
I don't know why this works...I've seen elsewhere (although I can't seem to find the post again) that some hugo themes don't play nicely with .html files, and prefer .md files, and that appears to be the case for the Even theme.
In sum: My workaround for now is thus to work on my posts, and when I'm done, knit the document with the option above, delete the .html file, and be on my way.
Caveat: blogdown seems to automatically re-render all the old posts when using Serve Site. According to this stack answer, Serve Site should only render documents that have undergone changes. Regardless, the old posts are most definitely being re-rendered, even when working on an unrelated post. I'm not sure if this behavior is attributable to blogdown per se, or the RStudio project.
I tried going to Tools -> Project Options -> Build Tools, and unchecking the boxes "Preview site when building", yet the behavior persists. Which means I will have to continuously delete these new .html files for all old posts every time a I make a change to any other file. Currently I only have one post, so not a big deal...yet.
If someone knows of a solution to this caveat, I would be extremely grateful. If I find one, I will edit this question and add it.
EDIT: it appears that blogdown will re-render the old post if there is no .html document present. Otherwise, it does not re-render it.
EDIT 2: Aha! According to the answer to this question, simply changing the file extension of the blog post from .Rmd to .Rmarkdown will produce a .markdown document instead of a .html document.

Minimal Bookdown added jpg reference not rendering image

I and attempting to render a single jpg image using the minimal Bookdown setup.
Everything builds and knits fine in the original minimal bookdown state. When I add this one line of code just below '# Prerequisites,' the book incurs errors during the build process.
I've researched the error solutions to extent of my brain cells but cannot seem to locate the solution. The line of code works perfectly fine in R markdown, so it's not a file or directory does not exist issue.
When I knit the book, it produces the image in the proper position.
![](/Users/brianlee/Dropbox (Personal)/__bookdown_dfc/__derivations/flow_diagram.jpg)
Error messages are provided in linked image[![enter image description here][1]][1].
[1]: https://i.stack.imgur.com/K0u4B.jpg
Try to use HTML instead <img src= "/Users/brianlee/Dropbox (Personal)/__bookdown_dfc/__derivations/flow_diagram.jpg">

Here() function doesn't change its directory after pushing the source code to github

I am writing a Rmd file, where it contains some knitted images. The Rmd file shows stuffs just as expected when looking at them on my own computer, but it cannot show the inserted images when uploaded to my github.
To knit the inserted images, I used here() function:
knitr::include_graphics(c(here("data/images/experiments_areaId2ad4/plots", "scatter_old.png"), here("data/images/experiments_areaId2ad4/plots", "scatter_new.png")))
On the github, the images cannot be shown, and as most html, there are tiny placeholders at the positions of each of the images. When I clicked on one of the place holder, it led me to a webpage that was 404.
I looked at the URL, it is like:
https://github.com/[my_github_account]/[my_github_repo]/blob/master/Users/[myname]/Desktop/[my_local_path]/[my_github_repo]/my_reports/data/images/experiments_areaId2ad4/plots/scatter_new.png
Obviously it has copied my local path from my computer to the github, so that the paths of these images are definitely not valid anymore.
However, I still want to use the here() function, so that when my collaborators pull my github updates, they can still interact with my projects without having to worry about screwing up directory.
Does anyone have a suggestion?
Thanks!

How to save images in r markdown html

So I know how to show images ![Caption](/path/to/image.png) but I want the image to be saved on the html file so when I open the html file on someone else's computer I should be able to see the image. I will get an error message saying the path is wrong if I try to knit the .Rmd file.
The image is referenced absolutely on my computer but I don't want that. Is there a way to do?
I apologize in advance if this question is a duplicate, but I'm having trouble finding a proper solution. Thanks
A simple solution would be to import the image into R and then print it.

R knitr html file picture locations when compiling through RStudio

When I make my knitr document, I see the html file in my directory. I load the file and it looks great.
However, I'm curious where the pictures are:
It gives me locations like:
img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAACQAAAAYACAYAAAAjFnetAAAEJGlDQ1BJQ0MgUHJvZmlsZQAAOBGFVd9v21QUPolvUqQWPyBYR4eKxa9VU1u5GxqtxgZJk6XtShal6dgqJOQ6N4mpGwfb6baqT3uBNwb8AUDZAw9IPCENBmJ72fbAtElThyqqSUh76MQ ...."
Where exactly is the image?
This IS the image directly encoded in html. http://en.wikipedia.org/wiki/Data_URI_scheme
see f.e. this stack overflow question: Embedding Base64 Images
kind greetings

Resources