Skip to content

Commit

Permalink
Added references to the QuartoNotebookRunner + example
Browse files Browse the repository at this point in the history
  • Loading branch information
svilupp committed Apr 20, 2024
1 parent 184eed1 commit a41858c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/src/outputformats.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ which can extend the range of output formats from your Literate.jl-formatted scr
Literate.jl will produce a `.qmd` file, which can be used as input to Quarto CLI to produce
a variety of output formats, including HTML, PDF, Word and RevealJS slides.

Once you convert your Julia scripts into QMD files with Literate, you have two options for running them. You choose between them via the YAML header.

1. Use Jupyter + IJulia (the default option, which can cause complications because of Python dependencies). Set `jupyter: julia-1.10` in the YAML header, where `julia-1.10` is the name of your IJulia kernel.
2. Use the new Julia-native [QuartoNotebookRunner](https://github.com/PumasAI/QuartoNotebookRunner.jl/). Set `engine: julia` in the YAML header.


##### Literate + Quarto syntax tips

- `# `(hashtag followed by a space) at the beginning of a line will be stripped and anything
Expand All @@ -115,12 +121,12 @@ a variety of output formats, including HTML, PDF, Word and RevealJS slides.
rendered as `#| echo: false` and would tell Quarto not to "echo" the outputs of the
execution (see [Guide: Executions
options](https://quarto.org/docs/computations/execution-options.html) for more commands).
- Make sure to always provide the YAML header and specify IJulia kernel when executing the
- Make sure to always provide the YAML header and specify which jupyter kernel or engine to use when executing the
file by Quarto, e.g.,
```
# ---
# title: "My Report"
# jupyter: julia-1.9
# engine: julia
# ---
```
Notice how all lines are escaped with a `# ` so Literate.jl knows to strip the hashtags
Expand All @@ -131,6 +137,10 @@ a variety of output formats, including HTML, PDF, Word and RevealJS slides.
outputs, make sure they are surrounded by empty lines (e.g., add an empty line before and
after the header) to help Quarto parse them correctly

!!! warning "Quarto CLI Pre-Release Required"
The above snippet uses the Julia-native engine with QuartoNotebookRunner, which requires the pre-release version of [Quarto CLI 1.5.29](https://github.com/quarto-dev/quarto-cli/releases/tag/v1.5.29) or later.
If you cannot use latest Quarto CLI release, you can use the Jupyter + IJulia engine instead, by setting `jupyter: julia-1.10` in the YAML header, where `julia-1.10` is the name of your IJulia kernel.

##### Configuring Quarto for Julia code execution

- Install [Quarto CLI](https://quarto.org/docs/getting-started/installation.html)
Expand All @@ -151,6 +161,8 @@ a variety of output formats, including HTML, PDF, Word and RevealJS slides.
quarto render my_script.qmd --to html
```

See `examples/quarto_report.jl` for an example of a Literate.jl script that can be converted to a Quarto report.
For more Quarto examples, visit the [QuartoNotebookRunner Examples](https://github.com/PumasAI/QuartoNotebookRunner.jl/tree/main/test/examples).

## [**4.2.** Notebook output](@id Notebook-output)

Expand Down
49 changes: 49 additions & 0 deletions examples/quarto_report.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# ---
# title: "Quarto Report Demo"
# author: "Zoro"
# date: "1/1/1900"
# format:
# html:
# code-fold: true
# engine: julia
# ---

# # Header 1
# For reproducibility, we first activate the project environment and add the necessary packages
# In practice, you can re-use your project environment - see examples with julia.exeflags
using Pkg; Pkg.activate(".", io=devnull)
Pkg.add(["DataFrames", "StatsPlots"])
using DataFrames, StatsPlots

# # Header 2
# I am a text

# There is a plot:
df = DataFrame(a=1:10, b=10 .* rand(10), c=10 .* rand(10))
@df df plot(:a, [:b :c], colour=[:red :blue])

# ## Sub-header

# I am a text explaining the second plot:
@df df scatter(:a, :b, markersize=4 .* log.(:c .+ 0.1))

# # Header 3

# Example of mixing markdown and code
##|echo: false
## We could suppress printing the number by adding semicolon, but echo: false is a quarto way to hide outputs
my_number=5

# Output cell:
##| output: asis
println("I will be formatted as a markdown. My number is: $my_number")

# The following lines will be removed from the report
# They show you how to execute this report
## This is how you convert this report into an HTML file #src
using Literate #src
Literate.markdown("quarto_report.jl", flavor = Literate.QuartoFlavor()) #src
## The open your commandline and run the following command: #src
## quarto render quarto_report.qmd --to html #src
## or #src
run(`quarto render quarto_report.qmd --to html`) #src

0 comments on commit a41858c

Please sign in to comment.