Displaying RMarkdown HTML output in the CANVAS LMS - html

I am trying to display R code and output in the CANVAS LMS (specifically within a page, not just as a separate html file). I have had no joy Googling this so hopefully someone can help.
What I have tried (as a simple test) but hasn't worked: In RStudio created a new RMarkdown HTML document (the basic default one with a sample table and sample plot). Used Knitr to create the html file. Opened HTML file and copied code into the LMS (raw html editor). This kind of works but doesn't show the plot and has some of the code that I didn't need to copy (see image).
Presumably there is a smarter way to do this but I can't find any good resources.

There were two issues here. I solved (1) and have identified but not fully solved (2)
One was that I should have been using output: html_fragment instead of html_document to get html to embed in to Canvas (otherwise it is trying to put html inside html and gets confused)
The second I haven't fully resolved but the issue is that when I hit save on the Canvas page the editor strips any base64 images (which is all the plots). I haven't worked out if this is a general issue or the particular editor that is being used on the version of Canvas I am working with.

Related

Python jupyter notebook after converting to html , numbering of markdown disappeared

I used Table of Contents(2) of Nbextensions to create Table of Contents. And the titles were created using markdown.
Every thing is working fine. I mean , it looks pretty good in notebook modus.
But after I had converted the ipynb file to html file , then the number of each title dispeared . I used menu: File->Download as -> HTML to do this.
I tried to use another option "File->Download as ->HTML with toc" to convert to html. Although it generated desired numbering , this is still not what I want, because it will generate not only an html file but also multiple images file if there are some plots in the notebook.
Does anyone have a good idea?
I just need a SINGLE html file with everything embedded .
The numbering of the Nbextensions will be present if you'll download the notebook to PDF (after installing the relevant packages).
Regarding the HTML version, I didn't find an answer yet and will be happy for help either.
Notebook uses different formatting for the content. Exporting option only provide you to save your code. So, that you can send it to others.
Better save the data in the python notebook form itself to maintain formatting. Even exporting you to PDF won't provide you true formatting as the notebook does. But it will be better than HTML.
But if you still want the HTML format, you can format it manually as a webpage. May the formatting get improved in next version of nbconvert.

How to provide a document preview as a thumbnail independent of file type

In gmail when a file is sent as an attachment to an email, the recipient(s) can see a small portion of the contents of the file before even hovering over it. Now I'm very curius and in fact interested in implementing this in my own application. I've tried inspect element but couldn't quite get how they do this. Ok, with images I can somewhat understand how it's done. But how about pdf, word or excel document? Do they take a snapshot of some portion of the file and store it along with the attachment to later show it inside a container? Has anyone been able to do this? Is just html and css enough?
May be you have found a solution....
But am just updating an answer i just found
If you use Krajee Plugin then you can get that type of preview of the file. Its just not giving gmail like file preview but also giving other type plugin to upload and preview the images and files(almost every type). Giving below the links for your reference.
File Preview Demo
File Preview Icon Demo

Automatically convert markdown to html on browser refresh

Paul Irish gave some amazing insight on web tooling this time during googleio 2013. So he was presenting some slides that had been parsed into html from a markdown source i.e a .md file.
However one thing that surprised me was when he edited the source markdown for the slides in the chrome dev tools sources panel and then hit refresh, the .md automatically compiled again into the html to be output on the browser. Now I understand that the changes he made to the markdown file in the chrome dev tools were made also on his local file saved on the computer, but how did the markdown file automatically get converted into the html file upon save and refreshing the browser?
I am a complete beginner with markdown and I would really like to have this functionality. Any help is deeply appreciated
The whole purpose of markdown is that it is both human readable and machine readable. It is designed to be converted to HTML.
Depending on the language you are using, there are markdown parsers that create HTML for you.
For example, for PHP.
So, as an example, to have your server show the contents of say, homepage.md, your index.php file could have something like this:
$filename = $_GET['file'];
$content = markdown( file_get_contents( "path_to_markdown/{$filename}.md" ) );
print $content;
And, to see it in your browser you would go to example.com/?file=homepage
I will do my best to answer this.
HTML Mark down is a shorthand syntax that can be interpreted by a web browser to format or render the page in html.
this is taken from Stack Overflow.
eg
The syntax is based on the way email programs
usually do quotations. You don't need to hard-wrap
the paragraphs in your blockquotes, but it looks much nicer if you do. Depends how lazy you feel.
So, like converting from a file in notepad ++ from text to html. The file will be formatted using the basic rules of that particular syntax.
It also must be remembered, that programs are not mind readers. If the mark down code is not valid, neither will the corresponding html code. Just as saving a text file that is "supposed" to be formatted in html. It won't save as a working html file if the syntax is incorrect.
Also, markdown is not a total replacement for real code. It cannot cover the breadth and depth of the true coding language. I could liken it to pseudocode, but that is more of a lateral example.
In answer to your latest comment, If a second file is created from a first file (and the format is altered) -( in this case from mark down to html) - If the first file is then edited, without overwriting the changes into the second file, it cannot expect to be altered.
This is a good link a fellow SO gave me:
https://stackoverflow.com/editing-help
Please feel free to edit, if I have made an error.
I haven't tried this extension for Chrome but it seems to automatically render markdown (.md) files in Chrome.
https://chrome.google.com/webstore/detail/markdown-preview/jmchmkecamhbiokiopfpnfgbidieafmd?hl=en
In Firefox, I use the following extension for the same functionality.
https://addons.mozilla.org/en-US/firefox/addon/markdown-viewer/
No need for a separate .html file, just save the text file with .md extension and open it in the browser.
Hope that helps.

Where to find HTML source code in document written with Word 2007?

In Word 2003 one can save as WEB PAGE and get document translatted into HTML coding.
You can use VIEW and see SOURCE CODE to get the HTML coding for that file.
In Word 2007 you can save as web page but I can't find how you VIEW the source code that was created with it.
What you need to do is right-click on the file and select Open With... and use notepad to view the HTML.
Shield your eyes; it's ugly, ugly code.
EDIT: To alleviate some of the bloat and make things more legible, I suggest http://textism.com/wordcleaner/ - I've had pretty good results with it in the past, but it only works for files up to 20kb.
For SO bonus points, check out Jeff's C# code here: Cleaning Word's Nasty HTML.
You can also change the extension of the .docx to zip, then view the contents. A .docx file is actually a zip file with several .xml files inside... but that probably won't give you what you're looking for.
If you've only got a simple HTML page (I can't imagine it being much more than that if it was wrote in Word) you can just view the source in your browser.

PdfSharp, GDI+ and HTML printing

I currently have a "PrintingWebService" that I call from an AJAX page with all the information that is needed to construct a highly customized PDF printout using PDF Sharp and the PDFSharp's GDI+ mode, which takes DrawString and other commands that work basically just like GDI+ only they are drawn to the PDF.
I then save the PDF file to a location on the webserver and return the file name from the web service, and the AJAX page opens a new window with the pdf file.
So far, it works well, however, there is one part of my AJAX page that I want to printout and I haven't come up with a solution for yet. I've got a string of the HTML content of a TinyMCE editor that I want to dispay in the bottom part of the PDF page.
I'm looking for some sort of tool I could use for this purpose. Even something opensource that prints to GDI+ I could use by taking the source code and translating it to use PdfSharp's GDI+ (the class names are like XGraphics, with each class having X before the GDI+ name).
If I have to I will limit what HTML can be generated by TinyMCE and write my own renderer, but that will be a big challenge, so I'm looking for other solutions first.
I've stayed away from a printer-friendly page approach because I wanted to construct a page that was a near identical of an existing WinForms printout, using my existing code. With PdfSharp I was able to convert all the code except the text area stuff (which used the RichTextBox and RTF in the WinForms version).
Tony,
I personally have used WebSupergoo's ABCPdf library with much success. You can actually render HTML directly to the PDF and it does fairly well in regards to accuracy.
Another free software that will allow you the flexibility of writing HTML to PDF that I have used in the past with much success is iTextSharp.
Otherwise, I think you'll have to write something to render HTML to GDI.
Either way, you may want to consider using an HttpHandler that you map to using your web.config to generate the PDF file. This will allow for you to render the PDF to a bytestream and then dump it directly to the user (as opposed to having to save each PDF receipt to the web server). It will also allow for you to use the .pdf extension in the page that returns the receipt (PurchaseReceipt.pdf could be mapped to a HttpHandler)... making it more cross-browser friendly. Older versions of Adobe / Browsers will not display correctly if you start throwing a PDF byte stream from an ASPX page.
Hope this helps.