Knitted HTML not rendering properly, showing raw html only

When knitr to html from my project folder and I open it up in a browser the html file looks the way I want it. Very similar to the rmd file. But after loading it to github, when I try opening the file I get an error that github can't process right now and when it opens up, the only thing that shows is the raw html for the knitr file.

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />




<title></title>

<script src="data:application/x-javascript;base64,LyohIGpRdWVyeSB2MS4xMS4zIHwgKGMpIDIwMDUsIDIwMTUgalF1ZXJ5IEZvdW5kYXRpb24sIEluYy4gfCBqcXVlcnkub3JnL2xpY2Vuc2UgKi8KIWZ1bmN0aW9uKGEsYil7Im9iamVjdCI9PXR5cGVvZiBtb2R1bGUmJiJvYmplY3QiPT10eXBlb2YgbW9kdWxlLmV4cG9ydHM/bW9kdWxlLmV4cG9ydHM9YS5kb2N1bWVudD9iKGEsITApOmZ1bmN0aW9uKGEpe2lmKCFhLmRvY3VtZW50KXRocm93IG5ldyBFcnJvcigialF1ZXJ5IHJlcXVpcmVzIGEgd2luZG93IHdpdGggYSBkb2N1bWVudCIpO3JldHVybiBiKGEpfTpiKGEpfSgidW5kZWZpbmVkIiE9dHlwZW9mIHdpbmRvdz93aW5kb3c6dGhpcyxmdW5jdGlvbihhLGIpe3ZhciBjPVtdLGQ9Yy5zbGljZSxlPWMuY29uY2F0LGY9Yy5wdXNoLGc9Yy5pbmRleE9mLGg9e30saT1oLnRvU3RyaW5nLGo9aC5oYXNPd25Qcm9wZXJ0eSxrPXt9LGw9IjEuMTEuMyIsbT1mdW5jdGlvbihhLGIpe3JldHVybiBuZXcgbS5mbi5pbml0KGEsYil9LG49L15bXHNcdUZFRkZceEEwXSt8W1xzXHVGRUZGXHhBMF0rJC9nLG89L14tbXMtLyxwPS8tKFtcZGEtel0pL2dpLHE9ZnVuY3Rpb24oYSxiKXtyZXR1cm4gYi50b1VwcGVyQ2FzZSgpfTttLmZuPW0ucHJvdG90eXBlPXtqcXVlcnk6bCxjb25zdHJ1Y3RvcjptLHNlbGVjdG9yOiIiLGxlbmd0aDowLHRvQXJyYXk6ZnVuY3Rpb24oKXtyZXR1cm4gZC5jYWxsKHRoaXMpfSxnZXQ6ZnVuY3Rpb24oYSl7cmV0dXJuIG51bGwhPWE/MD5hP3RoaXNbYSt0aGlzLmxlbmd0aF06dGhpc1thXTpkLmNhbGwodGhpcyl9LHB1c2hTdGFjazpmdW5jdGlvbihhKXt2YXIgYj1tLm1lcmdlKHRoaXMuY29uc3RydWN0b3IoKSxhKTtyZXR1cm4gYi5wcmV2T2JqZWN0PXRoaXMsYi5jb250ZXh0PXRoaXMuY29udGV4dCxifSxlYWNoOmZ1bmN0aW9uKGEsYil7cmV0dXJuIG0uZWFjaCh0aGlzLGEsYil9LG1hcDpmdW5jdGlvbihhKXtyZXR1cm4gdGhpcy5wdXNoU3RhY2sobS5tYXAodGhpcyxmdW5jdGlvbihiLGMpe3JldHVybiBhLmNhbGwoYixjLGIpfSkpfSxzbGljZTpmdW5jdGlvbigpe3JldHVybiB0aGlzLnB1c2hTdGFjayhkLmFwcGx5KHRoaXMsYXJndW1lbnRzKSl9LGZpcnN0OmZ1bmN0aW9uKCl7cmV0dXJuIHRoaXMuZXEoMCl9LGxhc3Q6ZnVuY3Rpb24oKXtyZXR1cm4gdGhpcy5lcSgtMSl9LG

Github says "Sorry about that, but we can’t show files that are this big right now.)" and gives the option to view raw, the above is a sample that.

I copied the html file to my desktop and opened it in a browser from there and the same thing happened. What do I have to do so that I can open the knitr html file properly without it having to be in the project file?

Hi @sshake08! Welcome!

A few of questions to help understand what might be going wrong:

  • When you say, “I loaded it to github”, do you mean that you uploaded the file as a GitHub Gist, or that you pushed a commit that included the file to your repository — or something else?
  • Is the file in a public repository? If so, it would help to have a link to it! :grinning:
  • In the YAML header of the R Markdown file that generated the HTML, did you have the option self_contained: true?

I’m not quite sure what this part means: did the file display as raw HTML in your browser, or did it display as text but without the expected formatting?

FYI, GitHub never shows rendered HTML files, unless they’re in a special GitHub Pages repository. All other HTML files are shown as source, though there are various third-party services that attempt to work around this. GitHub does show Markdown files rendered as HTML, however, which you can take advantage of by using the github_document R Markdown format.

1 Like

Here's what I can quickly answer

Thanks!

Thanks for the link! It looks like your HTML document was generated as “self contained” (all the scripts and images are encoded right into the document, rather than linking to external files).

Being self-contained is what makes the HTML file large (for HTML), which is why GitHub is only offering a raw view. However, even if it were smaller, GitHub would only be showing you a highlighted source view, not the rendered view. As I mentioned above, GitHub doesn’t let you view rendered HTML outside of GitHub Pages.

But nothing seems to be wrong with that version of the file — I just downloaded it, and it opens and displays as expected on my machine (I can see all the plots, and it has the usual formatting).

Can you describe in more detail the steps you took when you had trouble viewing a copy of the HTML file in your browser?

If you want people who are browsing your repo on GitHub to be able to read a rendered version of your report, the github_document output format is probably going to be a better bet than HTML. And, of course, you can use R Markdown to knit the same Rmd file to both formats, so that one is available for easy download and the other is there for easy online viewing.

1 Like

Thanks for getting back to me so promptly. Just for further clarification "you can use R Markdown to knit the same Rmd file to both formats, so that one is available for easy download and the other is there for easy online viewing.". What do you mean by "both formatts?

Also I tried launching it from my mackbook desktop, it's rendering properly.

1 Like

You can knit the same document to both the html_document and the github_document format. More than one output format can be specified in the YAML header of an Rmd:

---
output:
  html_document:
    toc: true
    self_contained: true
  github_document:
    toc: true
---
1 Like

I'm still having trouble. I entered the YAML as you did and now it's rendering differently. Not what to do from here. I loaded the new document to github and the same thing is still happening which means I missed something in your instructions.
?

GitHub does not serve HTML pages; I believe that this is by design to prevent overload. They see themselves as code repository, not a static website provider.

There are several hacks about that, see

My favorite hack is githack, but there are other options..
http://raw.githack.com/

In your case the url would be https://rawcdn.githack.com/sshaikh08/White-Wine-Data-Analysis/38abb8db00e53ba15797306919203ed3c788c6b4/WhiteWineExploratoryDataAnalysis.html and it seems to be working...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.