1

I want to make a GitHub repository with data analysis driven with R in Jupyter Notebook (JupyterLab editor). For some reason Github makes total mess out of those notebooks when opened via the website. However, when I've cloned/pulled this repository, the files worked again totally fine in JupyterLab or Jupyter Notebook. So this is not a git issue.

Is there a way to force Github to properly render the notebooks with R kernel? Some time ago it was possible in Github, and I've used that several times.

For example, this code:

df.fer <- read.xlsx("../data/data.xlsx",sheet='fermentation')

# adjusting data, creating factors, adjusting data types, etc.
df.fer$`Volume.[Nml]` <- as.numeric(df.fer$`Volume.[Nml]`) # some text artifacts are present so as.numeric has to be used
df.fer$`disintegration.temp.[oC]` <- factor(df.fer$`disintegration.temp.[oC]`,
                                            ordered=TRUE, levels=c('in.','b.d.','45','50','55','60'))
df.fer$`disintegration.time.[h]` <- factor(df.fer$`disintegration.time.[h]`,
                                           ordered=TRUE,levels=c('in.','0','24','48'))

# creating new factor to distinguish between case No and experiment included in a case
df.fer$case.exp <- factor(paste(df.fer$case.No, df.fer$experiment.No,sep='-'))


# changing the column names for simpler manipulation
df.fer.original.col.names <- colnames(df.fer) # just in case
df.fer.simlified.col.names <- c('day','volume','original.column.header','description','composition','inoculum.weight',
                                'co-substrate.weight','dis.temp','dis.time','case','experiment','disintegration.tab','case.exp')

colnames(df.fer) <- df.fer.simlified.col.names

# removing one series - it turned out to be invalid
bad.series_case.exp <- '35-1' # it will be removed in some analyses
df.fer <- df.fer[df.fer$case.exp != bad.series_case.exp,]

Renders in Github as:

This is how it looks in gitHub

3
  • 1
    As a Jupyter Project the offerings from the Jupyter Developers are the standard ways of interacting with .ipynb. Anything else is a third party and the support is subject to their whims. The Jupyter Community provided solution to render .ipynb files, no matter the kernel is, nbviewer. You can point it at essentially any .ipynb file on the internet. Here is an example nbviewer rendering of a notebook file with the R kernel stored on GitHub. However, ... Commented Feb 9, 2024 at 19:57
  • 1
    <continued> you can see here this is what it looks like in the preview rendering provided for developers by GitHub. While the nbviewer view looks better and is clearly the one you'd share with non-developers, I'm not seeing the issues you share in general. But yours does mess with GitHub;s render, but is fine in the nbviewer solution! See nbviewer rendering of your code here. The gist of your code is at ... Commented Feb 9, 2024 at 20:13
  • 1
    <continued> gist.github.com/fomightez/1f30f333c20af531934694813a3268bf and looks bad as your report. By the way, screenshots alone are discouraged on StackOverflow. And in this case you can understand why when you realize this would have been much quicker if you shared the code you put in the post here with a link to it at posted at GitHub, too. You can make the URL for pointing nbviewer at it in the main form or study the pattern of nbviewer links to GitHub content and edit the URL by hand to point at it. So that would have been all I needed to do to show nbviewer use was a solution. Commented Feb 9, 2024 at 20:17

1 Answer 1

2

When this was posted, GitHub has introduced an issue that messed up rendering of a lot of types of notebooks, in particular those from Google Colab not having the line endings of code respected. The example here also seemed affected in several ways.
GitHub has fixed this all now, see here. (For example, the OP's test notebook now works fine again in GitHub's rendering, see here.)
Note though nbviewer rendering (here for the test) remains a more full-featured choice and requires no more than altering the URL.


FROM THE ORIGINAL REPLY, before GitHub fixed the underlying issue:

You have a combination of characters in there that is messing up GitHub's rendering, specifically the dollar signs, line endings, and possibly more.

Luckily, the provided solution for rendering .ipynb files works great in this case.

Compare:

Your code rendered at nbviewer, while hosted at GitHub can be seen live in your browser here. Screengrab:

enter image description here

GitHub is only meant to be a quick preview for developers.

Your code rendered at GitHub where it is hosted
here. Screengrab of it:

enter image description here


The details:

nbviewer is the Jupyter community-provided solution for viewing and sharing notebooks 'static' form. A lot of javascript-based features, like Plotly plots, work in nbviewer's renderings. Plus, the nbviewer renderings aren't embedded inside a GitHub page and thus display with less cruft surrounding them are more inviting for those who aren't developers and better for sharing.

Other examples of GitHub's preview falling short while nbviewer shines:

Sign up to request clarification or add additional context in comments.

11 Comments

I just ran another two to see if it was that they had to be freshly added. GitHub: two recently run notebooks render okay on GitHub [here]gist.github.com/fomightez/116805a5353b5873fef62e8eefd899ee). They look better on nbviewer #1 here and ...
<continued> #2 here. "No character encoding or strange characters caused that." Yes, your dollar signs and maybe more caused that. I wasn't looking to pick apart the specifics, past the dollar signs, since nbviewer is a better choice. Dollar signs are triggering the use of Latex as is common. I didn't test though if that is all. That is what I meant by combination of characters.
Is it possible to share the test?
<continued> before, it is important to keep in mind rendering of Jupyter .ipynb files is not their priority and Jupyter's offering of nbviewer provides a much more feature rich possibility that is compatible with you hosting your content almost anywhere public, I think. (It is possible to install nbviewer and use it in conjunction with private content, too.)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.