How to insert image on Jupyter Notebook - jupyter-notebook

I am using macOS and trying to add an image (png) file on Jupyter Notebook markdown cell, but it keeps generating an error message that they cannot find the png file. I am not sure what is wrong with my following two codes:
![alt text]("~Users/jj/pythonworkspace/what.is.numpy.png" "What is Numpy?")
Alternatively,
<img src="~Users/jj/pythonworkspace/what.is.numpy.png">

You shouldn't be using quotations around your path or links. Also i think you meant to have an additional / after your home directory or maybe not have ~ at all. The path you're providing isn't following the macOS conventions.
You can test if that path is valid by going into terminal and running
ls /path/you/are/testing
try
![What is Numpy?](/Users/jj/pythonworkspace/what.is.numpy.png)

Related

Quarto Render not Rendering

I am trying out Quarto, I am using R version 4.2.1. When I go to RStudio, File -> New File -> Quarto Document and create a new document, when I try to render via the RStudio Render button, I get the error 'C:/Program' is not recognized as an internal or external command, operable progam or batch file
I have tried installing R in a directory which has no white space in the installation path, but this did not resolve the issue.
UPDATE: on doing quarto check as suggested in comment gave me
Not sure what that means, but I was able to solve the problem by ensuring my qmd quarto file did not have white space in its name (replaced white space with underscores. The error then went away.
On changing my qmd file name, from HVL campaign.qmd to HVL_campaign.qmd (removing the white space), the rendering works. The error message was misleading though, that may need to get looked at...?
This error pops up if there is a space anywhere in the filepath unfortunately. I am running into this error when I try to make a new project in a directory that has a filepath with a space (thanks onderive...)

How to run Python, R, Octave or Julia using BowPad?

I try using a very light-weighted editor BowPad to edit and run codes.
Take running R as an example, which has been added to Windows PATH Environment Variable D:\R\R-3.6.2\bin\x64
I try to take some following steps:
I built a test.r writing some testing line codes as 1+2; plot(1:10)
Menu --> Run --> Configure custom commands
Command Name: run R
Command Line: D:\R\R-3.6.2\bin\R.exe $(SEL_TEXT)
$(LINE) The line where the cursor is
$(POS) the position where the cursor is
$(TAB_PATH) the path to the file of the active tab
$(TAB_NAME) the file name without extension of the current tab
$(TAB_EXT) the file extension of the current tab
$(TAB_DIR) the directory of the file of the active tab
$(SEL_TEXT) the selected text or the word at the cursor position
$(SEL_TEXT_ESCAPED) like $(SEL_TEXT) but escaped, useful for urls
When I press to choose run R to run the code, something wrong happens!
It will open a Rterm(64-bit) window each time when I run R!
it shows RGUMENT '1+2' __ignored__ or ARGUMENT 'plot(1:10)' __ignored__
Did I missing something ? BTW, can we set some shortcuts keys for running Python, R, Octave or Julia?
Also, when I reach the homepage of BowPad for more information, little usage of this software can be found!
R.exe refers to Rterm. You can use Rgui.exe instead but that won't automatically process arguments. I think what you likely want is to send the selected text to a running R session rather than starting up a new R session each time.
To do that
download this file and optionally place it on your path https://raw.githubusercontent.com/ggrothendieck/batchfiles/master/clip2r.js
in the Bowpad Run | Configure window configure a Run R command as the following (or if clip2r.js is not on your path use the entire pathname). It should be just like this with no arguments.
clip2r.js
From the Windows cmd line if Rgui is running we see that tasklist | findstr Rgui finds Rgui as the R gui process and you can create additional js scripts by editing clip2r.js replacing Rgui in the js script with whatever is the appropriate word to locate python, julia, octave or other R front end assuming again that they are running.
Now to invoke it from within Bowpad:
ensure that your Rgui session is already running and
from within Bowpad select the code you want to run and copy it to the clipboard and then invoke Run R. For example, to run everything use ctrl A ctrl C ctrl R 0 assuming that Run R is in position 0 in the configure menu. Alternately use the mouse with the Ribbon.
Regarding the comment about difficulty finding help, it looks like Bowpad is based on Scintilla so the documentation for it and the related SciTE editor likely apply to Bowpad too. You can also check the Bowpad source code on github.

Jupyter Notebook save to PDF without Code

This has been an ongoing issue for me, as I would love to use Jupyter Notebook to write my research reports, but have found it very difficult to export my Jupyter Notebooks to PDF without code and without large formatting errors.
I am able to download the notebooks as PDF, but have not found a way to hide the code, or have the PDF resemble the formatting of the notebook.
No solution I've found on SO has been sufficient for my issue, so it may be possible that this is not the intended functionality of Jupyter Notebook.
Have you tried this:
jupyter nbconvert path/to/your/ipynb --to=pdf --TemplateExporter.exclude_input=True
For more on the flags, you can refer to nbconvert config options
I have successfully converted .ipynb to .html exclude the code blocks
I followed the suggestion by 0xffff above but the PDF output did not behave as intended (code blocks were still included).
However, their suggestion inspired me to try converting to html first using the following call:
jupyter nbconvert path/to/your/ipynb --to=html --TemplateExporter.exclude_input=True
This behaved as intended, and from there, it was straightforward to print the output to PDF in a browser.
Regarding the issue with the --to=pdf flag, I've opened up an issue on the Jupyter Notebook git repo: https://github.com/jupyter/notebook/issues/3804. Will report back once I get a response.
nbconvert
nbconvert is an official package, and other answers have mentioned it. However, they did not mention there are two ways to convert to PDF.
The default option uses LaTeX, and it's often a pain to install:
jupyter nbconvert notebook.ipynb --to=pdf
A newer option is to use the webpdf converter, this does not require LaTeX
jupyter nbconvert notebook.ipynb --to=webpdf
Quarto
Quarto is the newest option. The defaults are prettier than nbconvert, and it has advanced features to customize the output PDF. However, it uses pandoc (and pandoc uses LaTeX), so you must install both first.
quarto render notebook.ipynb --to pdf
Quarto is a new project, and I often run into problems (I couldn't convert the sample notebook); however, the project is in active development and I'm sure it will get better.
Online converters
The last option is to use one of the many online services. The two main caveats are 1) You might not want to upload your notebooks to some random website, and 2) It's often unclear what engine they use to convert the notebooks. I've tried many of them with mostly negative results.
I created one online converter that uses nbconvert and deletes your notebook as soon as it's converted.
If you manually create the PDF, there is a simpler solution: add the following code block & execute it
from IPython.core.display import HTML
HTML('<style>.input, .jp-InputArea {display: none !important}</style>')
Code will disappear both in the "normal" UI and in print preview / export to HTML. Open print preview, generate the PDF - it looks great now, clear the output of this one cell to bring the code back, done

rmarkdown::render_site() Error in rmarkdown::render_site() : No site generator found

I am trying to knit together 3 files using this example: http://rmarkdown.rstudio.com/rmarkdown_websites.html
My files all share the same directory, which has been set in the RStudio build options. I literally copied the YML from the examples with my own file names. Even if I copy the examples directly, I get the same error.
I even ran the site_generator function from the RMarkdown Github: https://github.com/rstudio/rmarkdown/blob/master/R/render_site.R#L157
I noticed there are options for custom generators, which I do not want. All I would like to do is be able to knit together several markdown files into a single webpage and then create a navbar with tabs for each page/section.
I got the same error when attempting to build with an incorrectly named YAML config file. Specifically, the RStudio build option for a website requires that the config file be called _site.yml.
Verify that this file exists and that you're using the extension .yml rather than .yaml (even though the latter is preferred).
What helped for me was putting the line site: bookdown::bookdown_site back to index.Rmd.
lord, my issue was that i didn't set my working directly to where my _site.yml file and index.Rmd files are stored - the little things!
I fixed this error using this steps.
1-) RStudio-Tools-InstallPackages
2-) Install From should be CRAN Repository.
3-) write this command --> install.packages("install.packages("rmarkdown")")
4-) Click Install
And problem has gone... And this is output.
This error also appears when there is a format issue in the yaml section of index.Rmd.
In my case, I encountered the error when the opening "---" in index.Rmd had a couple of white spaces " ---".
If you are having this problem, I would recommend knitting index.Rmd by itself (not building the book) before trying anything more drastic.

Provide file download links in iJulia notebook results

I'd like to produce a data file that is downloaded by the user, either automatically or through a hyperlink.
For instance, is there an equivalent of this iPython approach for iJulia?
If I understand your question correctly, you're looking to auto-generate a link in Jupyter Notebook, such that people can download? If so, I do this in Vega.jl (so people can download PNG files of graphs) with the following:
window.setTimeout(function() {
var pnglink = document.getElementById(\"$divid\").getElementsByTagName(\"canvas\")[0].toDataURL(\"image/png\")
document.getElementById(\"$divid\").insertAdjacentHTML('beforeend', '<br><a href=\"' + pnglink + '\" download>Save as PNG</a>')
}, 20);
https://github.com/johnmyleswhite/Vega.jl/blob/master/src/render.jl#L65-L69
Basically, this code finds the div that the output is in (which is known at the time of Julia code running, before the output is rendered), then auto-generates an HTML link with the base64 representation of the PNG. Depending on your content, this obviously may differ (since the .toDataURL method has to have your file type in the method).
I translated from original FileLink definition to julia:
type FileLink
file_path::ByteString
end
type FileLinks
links::Vector{FileLink}
end
FileLinks(paths::Vector{ByteString}) = FileLinks(map(FileLink,paths))
function Base.writemime(st::IO, ty::MIME"text/html", fl::FileLink)
write(st, "<a href=$(fl.file_path) target='_blank'>$(fl.file_path)</a>")
end
function Base.writemime(st::IO, ty::MIME"text/html", file_links::FileLinks)
for fl in file_links.links
Base.writemime(st, ty, fl)
write(st,"<br>")
end
end
FileLinks(readdir("."))
Works on locally hosted IJulia/IPython/Jupyter server, but you may have problems with remote servers (eg Sage).
Using NBViewer to serve Jupyter notebooks statically works also with IJulia.
http://nbviewer.jupyter.org/gist/Ismael-VC/3d54a43d73f3a3fbd922
As shown in it's home page:
In this example I give NBViewer the link of one of my IJulia notebooks that is hosted in Gist, notice that GitHub/Gist now also renders Jupyter noteboks:
https://gist.github.com/Ismael-VC/3d54a43d73f3a3fbd922

Resources