Markdown section
In [1]
import pandas as pd
from bokeh.plotting import figure
from merkury.utils import output_bokeh
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
intro = """
# Merkury example
This page is an example report generated with [Merkury](https://github.com/ppatrzyk/merkury). It is meant to showcase different formatting possiblities.
This code block is written in markdown. You can use any valid markdown sytax. E.g. for tables:
| Column 1 | Column 2 | Column 3 |
| --------------- | -------- | ---------- |
| _Some value_ | 1 | 3 |
| **Other value** | 2 | 4 |
If you don't specify [formatting options](https://github.com/ppatrzyk/merkury#formatting-and-plots), output will be treated as python code.
"""
print(intro)
#MARKDOWN
#TITLE Markdown section
Out [1]
Merkury example
This page is an example report generated with Merkury. It is meant to showcase different formatting possiblities.
This code block is written in markdown. You can use any valid markdown sytax. E.g. for tables:
Column 1 | Column 2 | Column 3 |
---|---|---|
Some value | 1 | 3 |
Other value | 2 | 4 |
If you don't specify formatting options, output will be treated as python code.
print() in loop
In [2]
for i in range(10):
msg = f'Loop iteration: {i}'
print(msg)
#TITLE print() in loop
Out [2]
Loop iteration: 0
Loop iteration: 1
Loop iteration: 2
Loop iteration: 3
Loop iteration: 4
Loop iteration: 5
Loop iteration: 6
Loop iteration: 7
Loop iteration: 8
Loop iteration: 9
table from pandas
In [3]
print(iris.head())
#TITLE table from pandas
Out [3]
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
Raw HTML section
In [4]
html = """
<h3>Custom html header</h3>
<p>This code block is written in raw html.<p>
<img style="width: 50%" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48bGluZWFyR3JhZGllbnQgaWQ9InB5dGhvbi1vcmlnaW5hbC1hIiBncmFkaWVudFVuaX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ctNC42MzMtNC43MTkgMC0yLjU5NSAyLjA4My00LjY5MiA0LjYzMy00LjY5MnoiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgMTAuMjYpIi8+PHJhZGlhbEdyYWRpZW50IGlkPSJweXRob24tb3JpZ2luYWwtYyIgY3g9IjE4MjUuNjc4IiBjeT0iNDQ0LjQ1IiByPSIyNi43NDMiIGdyYWRpZW50VHJhbnNmb3JtPSJtYXRyaXgoMCAtLjI0IC0xLjA1NSAwIDUzMi45NzkgNTU3LjU3NikiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj48c3RvcCBvZmZzZXQ9IjAiIHN0b3AtY29sb3I9IiNCOEI4QjgiIHN0b3Atb3BhY2l0eT0iLjQ5OCIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iIzdGN0Y3RiIgc3RvcC1vcGFjaXR5PSIwIi8+PC9yYWRpYWxHcmFkaWVudD48cGF0aCBvcGFjaXR5PSIuNDQ0IiBmaWxsPSJ1cmwoI3B5dGhvbi1vcmlnaW5hbC1jKSIgZD0iTTk3LjMwOSAxMTkuNTk3YzAgMy41NDMtMTQuODE2IDYuNDE2LTMzLjA5MSA2LjQxNi0xOC4yNzYgMC0zMy4wOTItMi44NzMtMzMuMDkyLTYuNDE2IDAtMy41NDQgMTQuODE1LTYuNDE3IDMzLjA5Mi02LjQxNyAxOC4yNzUgMCAzMy4wOTEgMi44NzIgMzMuMDkxIDYuNDE3eiIvPjwvc3ZnPgo=" />
<p>
In addition to writing content manually, any python package that produces custom HTML output can be used here.
See printing pandas dataframes and plotting with bokeh below.
</p>
"""
print(html)
#HTML
#TITLE Raw HTML section
Out [4]
HTML table from pandas
In [5]
iris_html = iris.head(10).to_html(border=0)
print(f"<h3>Iris dataset</h3>{iris_html}")
#HTML
#TITLE HTML table from pandas
Out [5]
Interactive bokeh plot
In [6]
colors = pd.DataFrame({"species": ["setosa", "virginica", "versicolor", ], "color": ["blue", "green", "red"]})
iris = iris.merge(colors, how="left")
plot = figure(
title="Iris species",
x_axis_label="petal_width",
y_axis_label="sepal_width"
)
plot.circle(
iris["petal_width"],
iris["sepal_width"],
fill_color = iris["color"],
size = 10
)
print(output_bokeh(plot))
#HTML
#TITLE Interactive bokeh plot