rmarkdown
rmarkdown copied to clipboard
Display R notebooks on github
Is there any integration between github and Rnotebooks? Like the one with jupyter notebooks, that are nicely displayed on github. I've tried to save the notebooks in different formats (.html, .nb.html, .pdf) but it does not work. Moreover, is it a way to integrate interactive features (plots with ggplotly for example)?
Thanks
This would be up to GitHub to render the .nb.html
files here. Not sure RStudio can do much about it.
My solution is to use GitHub Pages to render my notebooks. I create directories named after specific notebooks (say, topic
), and then have an index.Rmd
file that generates the index.nb.html
file. I then create a symlink called index.html
pointing to index.nb.html
so that you can view the content by simply going to ../notebooks/topic
rather than ../notebooks/topic/index.nb.html
.
You'll need to create the symlinks on a *NIX system and then push it to GitHub, though, as far as I can tell -- I might be wrong!
- e.g. repo: https://github.com/RaoOfPhysics/phd-notebooks
- The individual notebooks (in their respective directories) are rendered here: https://raoofphysics.github.io/phd-notebooks/
- Example notebook: https://raoofphysics.github.io/phd-notebooks/benefits/
- The
index.html
file in that directory points to https://raoofphysics.github.io/phd-notebooks/benefits/index.nb.html - The
.Rmd
file can be grabbed here: ~~https://raoofphysics.github.io/phd-notebooks/benefits/index.nb.html~~ https://raoofphysics.github.io/phd-notebooks/benefits/index.Rmd
- The
You can also use ggplotly()
to make the plots you render interactive. I've not done so for these notebooks, although I have tested it.
Agree with @RaoOfPhysics, perhaps this issue belongs to github (unless @yihui can come up with a way to generate a symlink when rendering the notebook, but I am sure there are many reasons not to).
I didn't want to use a first page and then divide by topics, since I just wanted to have a single topic within my repo. On Windows 10, I did it like this:
- Open a cmd prompt as administrator
- Navigate to your repo
cd "C:\Users\MyName\Documents\GitHub\MyRepo"
- Generate a symlink with
mklink
. This is used asmklink "linkfile" "to_this_file"
. In this case:mklink "index.html" "index.nb.html"
- Commit and push to your repo
Here is a site working like this
@karthik Do you know anyone at GitHub that it would be productive to follow up with on this?
@jjallaire Brandon Keepers might be a starting point (@bkeepers). He helped merge the issue with rendering Rmd files.
@bkeepers It would be awesome if we could get R Notebooks to render on GitHub the same way that Jupyter notebooks currently render. This should be very straightforward as R Notebooks are actually valid HTML files that can be rendered as-is (see http://rmarkdown.rstudio.com/r_notebooks.html#notebook_file).
Here's a simple example: https://github.com/karthik/rmarkdown-notebook/blob/master/test.nb.html
If the .nb.html file was rendered inside an iframe (the same way that Jupyter notebooks are currently rendered) then that would be all we need.
Let us know if there is someone at GitHub we should be working with on this. We are happy to do any implementation legwork required if you let us know what the shape of this work is.
Hi @bkeepers, we just want to check again if there is a chance to support R Notebooks on Github, since many users have expressed interest in it. Thanks!
I reached out to Github Support via email and they responded today:
I'm currently discussing with the team internally where would be the best place to report your request to get some notice.
We should be back in touch soon!
It is possible to publish my R notebooks in Github. I followed these steps:
a) I installed the R kernel in my Jupyter environment.
b) I run my R commands in Jupyter using the R kernel
c) I downloaded it and saved it as an ipynb file.
d) I uploaded this file to my Github repository. Clicking the file the R notebook is shown.
You can see my R notebook at
https://github.com/eacunafer/Rlabs-para-Analisis-de-datos/blob/master/r_notebook1.ipynb
The only drawback is that other users do not have a way to known is the notebook is for Python or R, due to the extension of the file. But I think this can be fixed.
Hi @eacunafer. Indeed, that solution works for those using Jupyter Notebooks, but it won't work for those of us who use R Notebooks instead.
You are right. But My advice for people interested in data science is to learn both R and Python
@eacunafer: Of course, but that's not the point of this issue. And FYI, you can use python within R Notebooks if you want.
Below is the last thing I heard on this in an email 1/25/18 from the github team. As of 3/21/18 haven't seen anything pop up on their blog.
Our issue tracker isn't publicly accessible, but you can keep up to date with new features by following our blog: https://github.com/blog
(To keep an eye on it, I set up a google alert for "notebook site:blog.github.com")
I like to put preview hyperlinks to documents of interest on my projects. If those files are HTML, I can use the htmlpreview syntax in my target and the page will display.
sample target url:
http://htmlpreview.github.com/?https://github.com/TheMitchWorksPro/DataTech_Playground/blob/master/R_Misc/TMWP_CrapsGameSimulation_R.html
Example readme where this is used:
https://github.com/TheMitchWorksPro/DataTech_Playground/blob/master/README.md
I have both Python and R Jupyter notebooks on my project as well. Both preview if you click the link to view the individual file on GitHub. But I do not yet see a simple way to build a hyperlink target for them to use in my readme.md file like what I did with HTML above. Given the content of this issue, it would be great (if possible) if the solution you deployed took a form that enabled this capability.
A possible hack I am experimenting with, but this may break and have to be edited each time I roc-commit the content ... This URL seems to work right now:
https://render.githubusercontent.com/view/ipynb?commit=24a4a32ee885d4ceb6166c83331decc2a44ed900&enc_url=68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f5468654d69746368576f726b7350726f2f44617461546563685f506c617967726f756e642f323461346133326565383835643463656236313636633833333331646563633261343465643930302f525f4d6973632f525f4d616769635371756172655f4578706c6f726174696f6e2e6970796e62&nwo=TheMitchWorksPro%2FDataTech_Playground&path=R_Misc%2FR_MagicSquare_Exploration.ipynb&repository_id=87484008&repository_type=Repository#ff6e4cb6-05b3-43c9-96d8-3117f999122f
Above is source of the iframe on the page for my R notebook where git displays it. I tried hacking together the target of the desired R Notebook with the start of the above but this formed an invalid request (probably to be expected given all the arguments that make the above possible):
https://render.githubusercontent.com/view/ipynb?https://github.com/TheMitchWorksPro/DataTech_Playground/blob/master/R_Misc/R_MagicSquare_Exploration.ipynb
I agree with @RaoOfPhysics that rendering the .nb.html
file would be the cleanest resolution for this.
Until then, you could post to GitHub a Jupyter notebook generated from the .Rmd
file. This is similar to what @eacunafer already suggested - I'm only pointing here at how to (semi) automatically generate the .ipynb
file.
Requirements
- jupyter, and a R kernel
- A package that allows conversion/edition of
.Rmd
files as notebooks in Jupyter, among notedown (many github stars), ipymd, this fork (seems to offer a command line conversion between.nb.html
and.ipynb
) or nbrmd (mine)
In the case of nbrmd, a synchronized .ipynb
notebook is maintained up-to-date. Outputs are stored there, while inputs are taken from the .Rmd
. This means you can edit the .Rmd
file in both rstudio and jupyter, and will just need to refresh and re-execute the notebook in Jupyter (with a R kernel) before exporting the .ipynb
to Github.
Has there been an update to this issue? A simpler way of displaying R Notebooks like Jupyter notebooks would be great!
@bkeepers Is there an up to date contact at GitHub who we could follow up with on this? I think it would be relatively straightforward to implement (mostly just a matter of sandboxing the notebook as you already do for ipynb -- no "rendering" will be required since the notebook is already in HTML format).
@bkeepers any word on this?
As a workaround for now, rendering as github_document
might be an option: https://rmarkdown.rstudio.com/github_document_format.html
I would also love to have this feature. I often use Jupyter notebooks for demo and examples because I know it will render on github. The same should be possible with Rmd files. (The purpose is kind of the same but with less json clutter... off topic...)
I mean github will go through the trouble run something like nbconvert
to render ipynb to html. Why are they not able to render Rmd to html? That does not make any sense as an excuse.
Yes, rendering of Rmd
files would be really nice!
Can anyone make an addin to do this automatically? That would be great!
Would love an update on this issue from the Microsoft/Github dev team.
How is this still not implemented on GitHub? Seems like such a simple thing. And R has a pretty large user base.
Might as well add my support for this. I've only just discovered using R notebooks rather than just plain workflow scripts and it'd really changed how I work.
I agree, seriously no update on this? I would really benefit of sharing nb.html files here....
I agree, seriously no update on this? I would really benefit of sharing nb.html files here....
Yes, any update on this? Would be so nice...
Unfortunately, no. We contacted Github Support (twice, I think, in 2018 and 2019), and there has not been any update yet.
Perhaps @revodavid could help out with this? David, currently Jupyter notebooks ipynb files are rendered in GitHub within an iframe. The R equivalent is the .nb.html file which could also be rendered in the same sort of iframe. It would be extremely useful to be able to publish these notebooks to GitHub. Anything you can do to get this going in the right direction would be much appreciated.
I understand that Rmd files are no longer rendered on Github at @yihui's request.
The way I handle this is to add a gh-pages
branch to the repository and then link to the HTML directly (say, from README.md), as in this example.
We're not talking about Rmd files, we're talking about fully rendered R Notebooks (.nb.html files). These are roughly analogous to .ipynb files in that they contain both code and output (as distinct from Rmd files). They are very easy to render since they are just HTML. If the HTML was put in an iframe like .ipynb currently is it would be extremely useful.