Пример #1
0
def test_renderers(content):
    r = Report()

    r.widget(content[0])

    assert isinstance(r.get_configuration().elements[0].content, content[1])
    with tempfile.TemporaryDirectory() as tmpdir:
        r.render(os.path.join(tmpdir, "index.html"))
Пример #2
0
def f(value: Optional[str] = None):
    r = Report()
    r.text("# Report served with the API")
    if value is None:
        r.text(
            """
No value provided.


Try to add a value in the search string.

For example [like this](http://localhost:8000?value="with a value")
""",
            name="Result here",
        )
    else:
        r.text(f"The value was {value}", name="Result here")
    return r.get_configuration()
Пример #3
0
import pandas as pd

from vizno.report import Report

products = pd.DataFrame({
    "Product": ["Tablet", "iPhone", "Laptop", "Monitor"] * 1000,
    "Price": [250, 800, 1200, 300] * 1000,
})

r = Report(title="My super report",
           datetime="The datetime",
           description="a very basic report")

r.widget(products,
         width=12,
         name="A table",
         description="with a *description*")
Пример #4
0
from vizno.report import Report

r = Report(
    title="The demo report",
    description=
    "This report showcases the grid system based on 12 vertical divisions",
)

r.widget("Size 1", width=1)
r.widget("Size 2", width=2)
r.widget("Size 3", width=3)
r.widget("Size 4", width=4)
r.widget("Size 5", width=5)
r.widget("Size 6", width=6)
r.widget("Size 7", width=7)
r.widget("Size 8", width=8)
r.widget("Size 9", width=9)
r.widget("Size 10", width=10)
r.widget("Size 11", width=11)
r.widget("Size 12", width=12)

r.widget("Size 1 (newline)", width=1, newline=True)
r.widget("Size 2 (newline)", width=2, newline=True)
r.widget("Size 3 (newline)", width=3, newline=True)
r.widget("Size 4 (newline)", width=4, newline=True)
r.widget("Size 5 (newline)", width=5, newline=True)
r.widget("Size 6 (newline)", width=6, newline=True)
r.widget("Size 7 (newline)", width=7, newline=True)
r.widget("Size 8 (newline)", width=8, newline=True)
r.widget("Size 9 (newline)", width=9, newline=True)
r.widget("Size 10 (newline)", width=10, newline=True)
Пример #5
0
import matplotlib.pyplot as plt

from vizno.report import Report

f = plt.figure()
ax = f.add_subplot(111)
ax.plot([1, 2, 3], [2, 1, 3])
ax.set_xlabel("Label")

r = Report(title="My super report",
           datetime="The datetime",
           description="a very basic report")

r.widget(f,
         width=12,
         name="A matplotlib widget",
         description="with a *description*")
Пример #6
0
import random

from bokeh.plotting import figure as bokeh_figure

from vizno.report import Report

r = Report(title="My bokeh", datetime="The datetime", description="a very basic report")

plot = bokeh_figure(plot_width=400, plot_height=300)
plot.circle(
    [random.random() for _ in range(100)], [random.random() for _ in range(100)]
)

r.widget(plot, name="A bokeh widget")
Пример #7
0
from vizno.renderers.code import CodeContent
from vizno.report import Report

r = Report()
r.widget(
    CodeContent(
        code="""
def do_something(argument):
    print(f"Hello {argument}!")
do_something("ok)
""",
        language="python",
    ))
Пример #8
0
from vizno.report import Report

r = Report(
    title="My super report", datetime="The datetime", description="a very basic report"
)


r.widget(
    "This one returns text",
    name="A second widget",
    description="with another *description*",
)
Пример #9
0
from vizno.renderers import ContentConfiguration, render
from vizno.report import Report


class CustomObject(pydantic.BaseModel):
    parameter: int


class CustomRenderConfiguration(ContentConfiguration):
    parameter: int


@render.register
def _(obj: CustomObject):
    return CustomRenderConfiguration(
        component="MyCustomComponent",
        component_module="./my_renderer.js",
        parameter=obj.parameter,
    )


r = Report()
r.widget(CustomObject(parameter=10))
r.render("./output")
r.widget(
    CustomObject(parameter=1000),
    name="It works with a name",
    description="and a description",
)
r.render("./output")
Пример #10
0
import pygal  # First import pygal

from vizno.report import Report

bar_chart = pygal.Bar()  # Then create a bar graph object
bar_chart.add("Fibonacci", [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])  # Add some values

r = Report()
r.widget(bar_chart)
Пример #11
0
import os

from vizno.renderers.mathjax import MathJaxContent
from vizno.report import Report

r = Report()
r.widget(
    MathJaxContent(text="""
When \(a \\ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
"""))
Пример #12
0
def test_basic_report():
    r = Report()

    r.widget(None)
    with pytest.raises(pydantic.error_wrappers.ValidationError):
        r.header(None)
    r.header("Some header")
    r.header("Some header", description="Some description")
    with pytest.raises(pydantic.error_wrappers.ValidationError):
        r.text(None)
    r.text("Some text")
    r.text("Some header", description="Some description")

    assert len(r.elements) == 5
    config = r.get_configuration()
    assert isinstance(config, ReportConfiguration)
    assert len(config.elements) == 5
Пример #13
0
sizes = [x * 5 + 5 for x in xs]
colors = [random.random() * 0.1 for x in xs]

fig = go.Figure()
fig.add_trace(
    go.Scatter(
        x=xs,
        y=ys,
        mode="markers",
        marker=go.scatter.Marker(size=sizes,
                                 color=colors,
                                 opacity=0.6,
                                 colorscale="Viridis"),
    ))

r = Report()
r.widget(fig, name="A plotly widget")
# # create a simple plot
# bar = plotly.graph_objs.Bar(x=['giraffes', 'orangutans', 'monkeys'],
#                             y=[20, 14, 23])
# layout = plotly.graph_objs.Layout()
# fig = plotly.graph_objs.Figure([bar], layout)

# # convert it to JSON
# fig_json = fig.to_json()

# # a simple HTML template
# template = """<html>
# <head>
#     <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
# </head>
Пример #14
0
import os

from vizno.renderers.latex import LatexContent
from vizno.report import Report

r = Report()
r.widget(
    LatexContent(text=open(
        os.path.join(os.path.dirname(__file__), "something.tex")).read()))
Пример #15
0
import matplotlib.pyplot as plt
import pandas as pd
import plotly.graph_objects as go
import pygal
from bokeh.plotting import figure as bokeh_figure

from vizno.renderers.code import CodeContent
from vizno.renderers.latex import LatexContent
from vizno.renderers.mathjax import MathJaxContent
from vizno.report import Report

xs = [random.random() for _ in range(100)]
ys = [x + random.random() * 0.1 for x in xs]

r = Report(
    title="The demo report",
    description="This demo report showcases the capabilities of vizno.",
)

r.header(
    "Python plotting libraries",
    description="""
`vizno` supports all the common Python plotting libraries.
""",
)

f = plt.figure()
ax = f.add_subplot(111)
ax.plot(xs, ys, ".")
ax.set_xlabel("Label")

r.widget(
Пример #16
0
import altair
import pandas as pd

from vizno.report import Report

chart = (altair.Chart(
    pd.DataFrame({
        "a": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
        "b": [28, 55, 43, 91, 81, 53, 19, 87, 52],
    })).mark_bar().encode(x="a", y="b"))

r = Report(title="My Altair",
           datetime="The datetime",
           description="a very basic report")

r.widget(chart, name="An altair widget")
Пример #17
0
import random

import altair
import matplotlib.pyplot as plt
import pandas as pd
from bokeh.plotting import figure as bokeh_figure

from vizno.report import Report

xs = [random.random() for _ in range(100)]
ys = [x + random.random() * 0.1 for x in xs]

f = plt.figure()
ax = f.add_subplot(111)
ax.plot(xs, ys, ".")
ax.set_xlabel("Label")

chart = (altair.Chart(pd.DataFrame({
    "a": xs,
    "b": ys,
})).mark_circle(size=20).encode(x="a", y="b"))

plot = bokeh_figure(plot_width=400, plot_height=300)
plot.circle(xs, ys)

r = Report.magic(title="Magic report",
                 description="A magically gathered report")