Share rCharts via IPython Notebook - github

I have been able to embed this map in an IPython Notebook (which is sweet), but I am not clear on how I can share this with folks not using the Notebook. I am familiar with the bl.ocks.org viewer. It's great for standalone examples, but I am looking to share the rest of the analysis in the Notebook along with interactive charts. Neither the HTML conversion of the Notebook nor the nbviewer rendering can locate the map (I get a 404 message).
After the first 404 (with this gist), I changed the viewer function to capture the github location of the map file (V2). I am not yet clear why, but that change stopped nbviewer from even rendering the surrounding materials. Any thoughts on a better way to go about this?

The trouble is that the map is saved as a local HTML file (rChart_map.html) and is hence not accessible to nbviewer when you are trying to view it online.
Even if you upload rChart_map.html to the gist, it won't show up due to path issues. Locally, you need to refer to it as /files/rChart_map.html in your IPython notebook, whereas online, it has a different path. I had posted this issue earlier on twitter using the #IPython tag, but got no responses on how to debug.
So where does that leave us. Well, fortunately, most modern browsers allow an iframe to contain inline HTML using the srcdoc tag. This allows the generated .ipynb file to be standalone, as seen here, at the end of the file.
The key is to use the following code. The first line creates an iframe with inline html of the map and stores it in the python variable map2. The second line imports the necessary python modules and the third line displays the HTML. Note that we use h2[0], since map2 is an array, due to conversion from R, which is vectorized.
map2 = %R paste(capture.output(map$show('iframesrc', cdn = TRUE)), collapse = '\n')
from IPython.display import display, HTML
HTML(map2[0])
For this to work, you will need to have rCharts version > 0.4.1.
I am interested in making it easier for rCharts to be used in IPython notebooks. So any suggestions/feedback is welcome.

Related

VSCode Jupyter Notebook, how to change presentation/add mimetypes (changing the notebook output renderer options)

I've referenced this question: Change mimetype for VSC Jupyter Notebook ouput
And thoroughly googled, but I still can't seem to change the mime type of my Jupyter Notebook. I have 2 .jpnyb files opened, one has the option of mimetypes of text/html, text/plain and the other gives a weird one of application/vnd.somemorewords
Here is a picture of what the difference between the two look like within the command palette when attempting to change the presentation. First file: https://ibb.co/yBkmVdz Second file: https://ibb.co/vhcz866
Where is the first file grabbing the mimetypes from? I can't find any information on a location of a file (settings.json has been edited) that just sets the standard across the board for the entire VS Code app. Please help if you can!
I've done a search of package.json files on my computer and looked at over 50+ files for some sort of information of the notebook display order and renderer.
I also tried changing the User settings for the work space referencing the question that I linked above.

What is the vscode command to open a file in preview

I wrote an extension for vscode. After installation the extension folder contains documentation in a markdown file. I want to provide a command that loads this file into the preview pane so it displays rendered with images and hyperlinks etc.
You can do this sort of thing interactively:
and I have the full path to the markdown file, so now all I need is details of the command that implements this context menu item.
Web search does not produce complete or usable results.
After cloning the VS Code repo and trawling through the source I discovered the markdown.showPreview and associated commands.
To give credit where due, Lex Li reported the corresponding package.json entry in a comment while I was looking.
Without parameters this previews the content of the active editor, but as I said in a comment, it supports an optional Uri parameter and the code looks like this:
let pathToManual = path.join(context.extensionPath, "manual.md");
let uriManual: vscode.Uri = vscode.Uri.file(pathToManual);
vscode.commands.executeCommand('markdown.showPreview', uriManual);
For information on constructing workspace relative paths see the answer from Mark. The joinPath method he uses requires a base path as a Uri which is conveniently available for the workspace but not for the extension path.
If you need information on things like showing preview to one side then given the dearth of documentation I recommend cloning the repo and searching it for "markdown.showPreview", then exploring nearby code. If you fold the methods it gets easier to survey your options.
Try:
vscode.commands.executeCommand("markdown.showPreview", vscode.Uri.joinPath(vscode.workspace.workspaceFolders[0].uri,'test.md'));
Your fileName there at the end of course. And that assumed you are in the first or only root of a workspace. You might be able to simplify it using:
vscode.Uri.path(<path to file)
instead of the joinPath that I used.

is it possible to view a question with a browser before importing it to Moodle?

I have created a XML file using R-exams out of just a single exercise to be imported to Moodle. I would like to view it before uploading it in the Moodle question bank. I tried to open it with Firefox and I can see some code but not the output and a message appear saying that the XML file does not seem to have a style sheet associated to it. Is there a way to find this style sheet and to see how the question comes out just using a browser like Firefox or Chrome?
To emulate how the R/exams exercises are converted to HTML by exams2moodle() and how Moodle displays mathematical content, it's best to use
exams2html(..., converter = "pandoc-mathjax")
In recent versions of R/exams the resulting HTML file then automatically loads the MathJax Javascript that enables correct rendering of mathematical content in all modern browsers (including Google Chrome). See also http://www.R-exams.org/tutorials/math/ for some general advice about math in HTML.
To the best of my knowledge there is no tool that would quickly display Moodle XML files in such a way that you can easily assess them.

Alfresco PDF thumbnail previews unreadable

Not sure this is the right stackexchange site but seems to be the place with the most question about Alfresco I can find so here goes.
Have Alfresco Community Edition 4.2.d installed on a RHEL5 64bit box (mainly default install bar using MySQL as a database locally). Uploading PDFs to the documentLibrary is fine and thumbnail previews and flash previews are generating. If the PDF has been processed by ABBYY OCR (which we have running on a separate server and is used to OCR scanned PDFs) then the flash preview generates fine but the thumbnail is incredibly dark and looks as if it has been attacked by a can of spray paint.
I initially thought it could be a ghostscript issue but have updated that to 9.14 and still getting this issue. I have also tried playing around with ImageMagik but I can't get a nice clear thumbnail to generate. I am guessing it is a switch in the convert command that Alfresco is using but I am struggling to work out a combination of switches that will work and then where Alfresco would store these parameters. Or indeed what switches are currently being used.
I was wondering if anyone had seen this behaviour before with ImageMagik previews in Alfresco 4.2.d? It seems something unique to PDFs that have been through the OCR process so I am guessing I will need to create a separate transformation for them at a later stage.
EDIT: So it was suggested that a later version of ImageMagick and GS should resolve it. I have therefore installed GS 9.14 and IM 6.8.9-0 (both compiled form source). Running the following from a command line:
convert /root/test1.pdf[0] /root/test1.png
results in a crystal clear image thumbnail preview. Thinking I was on to a winner I have amended the following lines in alfresco-global.properties to point to the system location of GS and IM:
img.root=/usr
img.dyn=${img.root}/lib
img.exe=${img.root}/bin/convert
img.gslib = /usr/local/share/ghostscript/9.14/lib/
and alfresco loads. However the thumbnail preview generated by Alfresco using the new version of IM and GS does not result in nice clean previews.
I am guessing that Alfresco is passing some command line switch during the conversion that is undoing the good work of the later versions of these programs. Does anyone know where the switches for thumbnail creation might be stored in Alfresco?
I guess it's related to transparency and default background black. I didn't find an easy way to add the required parameters to the script except to register a new transformer supporting more parameters like:
-fill white -opaque none

Hosting ipython notebooks on Github

I maintain a Github repository with currently two ipython notebook files.
My repository is here:
https://github.com/tschm/MosekRegression
When I try to open those files with the nbviewer, e.g. using
nbviewer.ipython.org
and inserting
http://nbviewer.ipython.org/urls/github.com/tschm/MosekRegression/blob/master/Data.ipynb
i get the 400 Bad Request Error. The file is good as it works when I make it available as a Gist. First research seems to indicate that this is a permission problem? I bet I do something stupid here...
Many thanks
Thomas
Expanding on #chuwy's answer, here's a breakdown of steps. The trick is to head to your file's page on github and then click on the "Raw" button:
then copy the url (minus the protocol string "http://"), and prepend it with "http://nbviewer.ipython.org/urls/"
So for example, if I have my iPython notebook:
https://github.com/watsonix/prediction_for_fun_and_profit/blob/master/statsmodel_outliers.ipynb
and I want to see it in the nbviewer, I click on "Raw" to get the URL:
https://raw.githubusercontent.com/watsonix/prediction_for_fun_and_profit/master/statsmodel_outliers.ipynb
which I use to form the URL:
http://nbviewer.ipython.org/urls/raw.githubusercontent.com/watsonix/prediction_for_fun_and_profit/master/statsmodel_outliers.ipynb
voila!
Valid link is http://nbviewer.ipython.org/urls/raw.github.com/tschm/MosekRegression/master/Minimum%20Variance.ipynb
Your link points to the github's html page with your file. You should give the raw file instead.
It now appears that gist automatically renders iPython notebooks! I have been using nbviewer, but I just noticed that GitHub renders the ipynb file perfectly.