Nbconvert export interactive figure - Jupyter - jupyter-notebook

I'm trying to export a jupyter notebook using nbconvert that maintains the interactive figure. The figure works fine in the notebook but it returns to a static image after using Nbconvert.
I've tried the following commands to maintain the interactive figure
!jupyter nbconvert Untitled.ipynb --to webpdf --template classic
!jupyter nbconvert --to webpdf --allow-chromium-download Untitled.ipynb
!jupyter nbconvert --to html --execute Untitled.ipynb
!jupyter nbconvert --ExecutePreprocessor.store_widget_state=False --to html --execute Untitled.ipynb
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact
x = np.linspace(0, 2 * np.pi)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
line, = ax.plot(x, np.sin(x))
def update(w = 1.0):
line.set_ydata(np.sin(w * x))
fig.canvas.draw_idle()
interact(update);
plt.show()
notebook:
Export:

Related

R markdown PDF renders in Rstudio but not in R console

Update: After hours worth of trying stuff, I figured it out from this thread. Basically, I just had to detach the package KableExtra in between each call to render(), and all of the PDFs rendered in RConsole.
I have a series of R markdown documents that render in RStudio by clicking on the "Knit" button. I'm trying to write a script that will render all of the documents at once instead of waiting to click the button after each one renders, but when I run it in the Console, I keep getting errors.
Calls to render are as follows:
render(input="path/markdown_file.Rmd",output_format="pdf_document")
Here's what I know:
Both RStudio and R Console are running R version 4.2.2
Both are using pandoc version 2.19.2
Both have current versions of the rmarkdown package
Both are using pdflatex to render the PDFs
Both are rendering HTML files using html_document with no issues
The error message I'm getting in RConsole is:
`! Undefined control sequence.
...r}[t]{llrrrrrrrrrrrrrrrrl} \toprule \textbf {metric} & \textbf... l.693 \end{tabular}}
Error: LaTeX failed to compile markdown_file.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See markdown_file.log for more info.`
The only difference I'm seeing is a slight difference in the calls to pandoc:
`"C:/Program Files/RStudio/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS markdown_file.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output markdown_file.tex --lua-filter "C:\Users\XXXXXXX\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\XXXXXXX\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\latex-div.lua" --embed-resources --standalone --highlight-style tango --pdf-engine pdflatex --variable graphics *--include-in-header "C:\Users\XXXXXXX\AppData\Local\Temp\RtmpoJICVK\rmarkdown-str196079161973.html"*`
The Knit button in RStudio has the last part in italics, but the R Console does not. It's some reference to a temp file, but it gets deleted immediately so I can't see what's in it.
Any ideas on how to fix this?

Why is R Markdown giving me a LaTeX error when trying to knit to pdf?

I am trying to knit a PDF document using R Markdown. The markdown successfully knits to 100% but upon trying to create the output file, it produces the following error:
output file: project_2_cusack.knit.md
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS project_2_cusack.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output project_2_cusack.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in'
! Output loop---100 consecutive dead cycles.
\end#float ... \#tempdima \penalty \#floatpenalty
\else \vadjust {\penalty -...
l.385 \end{figure}
Error: LaTeX failed to compile project_2_cusack.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See project_2_cusack.log for more info.
Execution halted
I have specified to save as PDF so unsure why it is trying to knit as a tex file.
Any suggestions on troubleshooting?

r knit to pdf/html: pandoc document conversion failed with error 2

The R Markdown file seems to work in Rstudio. The r Markdown file can be converted into word, but not pdf/html.(Yesterday it gave different problem, so I change my question here.)
Any help will be appreciated!
This is the context of my Markdown file:
---
title: "Test"
author: "Test"
date: "2018/9/8"
output: html_document
---
## R test
```{r test}
x<-rnorm(500)
y<-rnorm(x*10)
ls()
plot(x,y)
rm(x,y)
```
This is an test.
This is the outcome is I knit to html:
|...................... | 33%
ordinary text without R code
processing file: test.Rmd
|........................................... | 67%
label: test
|.................................................................| 100%
ordinary text without R code
/usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:bootstrap' --include-in-header /var/folders/_h/013l11r91m3gny4lqwsvh5qh0000gn/T//Rtmpfvxqld/rmarkdown-str268664475eb.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
output file: test.knit.md
--smart/-S has been removed. Use +smart or -smart extension instead.
For example: pandoc -f markdown+smart -t markdown-smart.
Try pandoc --help for more information.
error: pandoc document conversion failed with error 2
stop processing
This is the outcome if I knit to pdf:
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: test
processing file: test.Rmd
|.................................................................| 100%
ordinary text without R code
/usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
output file: test.knit.md
--latex-engine has been removed. Use --pdf-engine instead.
Try pandoc --help for more information.
error: pandoc document conversion failed with error 2
stop processing
A little background might help:
Pandoc is a Haskell binary (i.e. a distinct piece of non-R software), that is shipped with RStudio for sake of running RMarkdown conversion. It seems you are getting some deprecation warnings, like:
--latex-engine has been removed. Use --pdf-engine instead.
--smart/-S has been removed. Use +smart or -smart extension instead.
This tells me you probably have an older version of RStudio, thus an older version of Pandoc. You may want to reinstall RStudio to make sure you have the appropriate Pandoc version, then debug from there.
Also, make sure to reinstall knitr and rmarkdown with the newest versions.

Julia DataFrames format in pdf with nbconvert

How can I get a DataFrame in a Julia Notebook to output to a pdf with nbconvert and control the formatting like with knitr::kable or pander tables in an R-markdown document?
Julia notebook:
the following code cell
using DataFrames
A = DataFrame(randn(10, 7))
the pdf from nbconvert shows 10Œ7 DataFrames.DataFrame followed by an un-formatted table. Although display(A) and print(A) show different outputs in the notebook, the pdf from nbconvert shows the same output as the code cell above does in the notebook.
With the Python Markdown Notebook Extension, the following markdown cells display the table in the notebook, but in the nbconvert generated pdf, the DataFrame turns into a one dimensional array.
Test1
{{A}}
Test2
| |
|------|
|{{A}}|
How can I get output like kable or pander tables in a knitted R-markdown doc in a pdf from a Julia Notebook with nbconvert?
Also on Github.
From Github discussion, nbconvert cannot read the Markdown Notebook Extension html output. Tables should be output from code cells so nbconvert can output them to TeX -> pdf.
The next follow-on question about which Julia functions can do this best is on StackOverflow

rstudio knitr Error: pandoc document conversion failed with error 43

Windows7 Prof 64-bit
Rstudio Version 0.98.1091
Hello all,
I am receiving the following error when I try to use KnitR to create a PDF.
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" FirmsoftReportGenerator.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output
{....}
\Documents\R\win-library\3.1\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' had status 43
I have searched the forum and I found 2 references to this, and that led me to update my Rmarkdown package. However, I still receive the error.
My code consists of sourcing an R file, creating a table.
Then doing the following:
```{r outputSection, results="asis", echo=FALSE}
library(xtable)
print(xtable(overallSummary), comment=FALSE)
```
Total Raw Messages are: `r totalRawMessages`.
Any help in the right direction would be huge!
Thanks in advance
PS - The script does produce a PDF using a different CSV as a source.
The primary difference I notice with the newer source file is that one of the rownames has a space in the table I am trying to print.
PPS - When I manually replace the Row Name with spaces with "TEST1", everything works fine
rownames(overallSummary)[1] <- "TEST1"

Resources