Exemple #1
0
def gen_report_complex_with_files(datadir: Path,
                                  single_file: bool = False,
                                  local_report: bool = False) -> dp.Report:
    # Asset tests
    lis = [1, 2, 3]
    small_df = gen_df()
    big_df = gen_df(10000)

    # text
    # md_block
    html_block = dp.HTML(html="<h1>Hello World</h1>")
    html_block_1 = dp.HTML(html=h2("Hello World"))
    code_block = dp.Code(code="print('hello')", language="python")
    formula_block = dp.Formula(formula=r"\frac{1}{\sqrt{x^2 + 1}}")
    big_number = dp.BigNumber(heading="Tests written", value=1234)
    big_number_1 = dp.BigNumber(heading="Real Tests written :)",
                                value=11,
                                change=2,
                                is_upward_change=True)
    embed_block = dp.Embed(url="https://www.youtube.com/watch?v=JDe14ulcfLA")

    # assets
    plot_asset = dp.Plot(data=gen_plot(), caption="Plot Asset")
    list_asset = dp.File(data=lis, filename="List Asset", is_json=True)
    img_asset = dp.File(file=datadir / "datapane-logo.png")

    # tables
    table_asset = dp.Table(data=small_df, caption="Test Basic Table")
    # local reports don't support DataTable
    dt_asset = table_asset if local_report else dp.DataTable(
        df=big_df, caption="Test DataTable")

    if single_file:
        return dp.Report(dp.Group(blocks=[md_block, dt_asset]))
    else:
        return dp.Report(
            dp.Page(
                dp.Select(md_block,
                          html_block,
                          html_block_1,
                          code_block,
                          formula_block,
                          embed_block,
                          type=dp.SelectType.TABS),
                dp.Group(big_number, big_number_1, columns=2),
            ),
            dp.Page(
                plot_asset,
                list_asset,
                img_asset,
                table_asset,
                dt_asset,
            ),
        )
Exemple #2
0
def gen_report_with_files(datadir: Path,
                          single_file: bool = False) -> dp.Report:
    # Asset tests
    lis = [1, 2, 3]
    small_df = gen_df()
    big_df = gen_df(10000)

    # text
    md_block = dp.Markdown(
        text="# Test markdown block </hello> \n Test **content**")
    html_block = dp.HTML(html="Hello World</hello>")
    big_number = dp.BigNumber(heading="Tests written", value=1234)
    big_number_1 = dp.BigNumber(heading="Real Tests written :)",
                                value=11,
                                change=2,
                                is_upward_change=True)

    # assets
    plot_asset = dp.Plot(data=alt.Chart(gen_df()).mark_line().encode(x="x",
                                                                     y="y"),
                         caption="Plot Asset")
    list_asset = dp.File(data=lis, name="List Asset", is_json=True)
    img_asset = dp.File(file=datadir / "datapane-logo.png")

    # tables
    table_asset = dp.Table(data=small_df, caption="Test Basic Table")
    dt_asset = dp.DataTable(df=big_df, caption="Test DataTable")
    dt_pivot_asset = dp.DataTable(df=big_df,
                                  caption="Test DataTable with Pivot",
                                  can_pivot=True)

    if single_file:
        return dp.Report(dp.Blocks(blocks=[md_block, plot_asset]))
    else:
        return dp.Report(
            md_block,
            html_block,
            big_number,
            big_number_1,
            plot_asset,
            list_asset,
            img_asset,
            table_asset,
            dt_asset,
            dt_pivot_asset,
        )
Exemple #3
0
race_bar.update_layout(xaxis_title='assignment',
                       yaxis_title='average',
                       legend_title='Race',
                       legend_bordercolor='black',
                       legend_borderwidth=2,
                       barmode='group',
                       bargap=.3)

# Create report
r = dp.Report(
    dp.Page(
        label='Introduction',
        blocks=[
            dp.HTML(html),
            "The data has been compiled over 3 semesters, for the introductory computer science class CSE 1223.",
            dp.Group(dp.BigNumber(heading="Number of Students",
                                  value=num_students),
                     dp.BigNumber(heading="Class Average",
                                  value=str(class_average) + "%",
                                  change="2%",
                                  is_upward_change=True),
                     columns=2),
            dp.BigNumber(heading="Pass Rate", value=str(pass_rate) + "%"),
        ]),
    dp.Page(label='Deliverables',
            blocks=[
                f'### Labs',
                dp.Plot(lab_bar), f'### Homeworks',
                dp.Plot(hw_bar), f'### Projects',
                dp.Plot(project_bar)
            ]),
    dp.Page(label='Exam Grades',
Exemple #4
0
"""# Building a Datapane report

Now that we have a series of plots, we can create a report using Datapane. 

In addition to the visualizations, this report includes Datapane's `BigNumber` component to display top level KPIs, and our `DataTable` component to allow our viewers to filter, explore, and download the data themselves.

Although we could create a linear list of all blocks (similar to how they are displayed in this notebook), we can build a more powerful and accessible report by using Datapane's [layout components](https://docs.datapane.com/reports/blocks/layout-pages-and-selects). 

From these components, we are using `Group` to place the `BigNumber` blocks in two columns, have used the `Page` block to add multiple pages to our report, and are using the `Select` block to create tabs where users can choose their dataset. This results in a beautiful, interactive document which we can publish and share.

"""

dp.Report(
    "# Finance Model",
    dp.Group(blocks=[
        dp.BigNumber(value=f"${round(burn)}", heading="Monthly outgoings"),
        dp.BigNumber(value=f"${CURRENT_CASH_GBP}",
                     heading="Cash in bank",
                     is_upward_change=True,
                     change=7)
    ],
             columns=2),
    dp.Select(blocks=[
        dp.Group(blocks=[
            """This plot models cash and revenue, dependent on various other growth scenarios and based on this month's burn. 

- Blue area is cash remaining
- Orange line is the cumulative sum of all revenue
- Purple line is monthly revenue

> Drag the slider to adjust growth rate. The growth rate at which the blue area never crosses 0 is the growth you need to achieve **[Default Alive](http://paulgraham.com/aord.html)**.