def gen_report_with_files(datadir: Path, single_file: bool = False) -> dp.Report: # Asset tests lis = [1, 2, 3] df = gen_df(10000) md_block = dp.Markdown( text="# Test markdown block <hello/> \n Test **content**") list_asset = dp.File(data=lis, name="List Asset", is_json=True) img_asset = dp.File(file=datadir / "datapane-logo.png") plot_asset = dp.Plot(data=alt.Chart(gen_df()).mark_line().encode(x="x", y="y"), caption="Plot Asset") df_asset = dp.Table(df=df, caption="Test Dataframe Table") pivot_asset = dp.Table(df=df, caption="Test Dataframe PivotTable", can_pivot=True) if single_file: return dp.Report(dp.Blocks([md_block, plot_asset])) else: return dp.Report(list_asset, img_asset, df_asset, md_block, plot_asset, pivot_asset)
def test_full_report(tmp_path: Path): df = gen_df() name = gen_name() description = gen_description() source_url = "https://github.com/datapane/datapane" # create a basic report m = dp.Text("hello world!!") # Asset tests lis = [1, 2, 3] json_list: str = json.dumps(lis) plot = gen_plot() # create the DP fn = tmp_path / "json_list.json" fn.write_text(data=json_list) file_asset = dp.File(file=fn) json_asset = dp.File(data=json_list, is_json=True) plot_asset = dp.Plot(data=plot) list_asset = dp.File(data=lis, is_json=True) df_asset = dp.DataTable(df=df, caption="Our Dataframe") dp_report = dp.Report(m, file_asset, df_asset, json_asset, plot_asset, list_asset) dp_report.upload(name=name, description=description, source_url=source_url) with deletable(dp_report): # are the fields ok check_name(dp_report, name) assert dp_report.description == description assert dp_report.source_url == source_url assert len(dp_report.pages[0].blocks[0].blocks) == 6
def test_report(tmp_path: Path): df = gen_df() name = gen_name() headline = gen_headline() # create a basic report m = dp.Markdown("hello world!!") # Asset tests lis = [1, 2, 3] json_list: str = json.dumps(lis) plot = alt.Chart(df).mark_line().encode(x="x", y="y") # create the DP fn = tmp_path / "json_list.json" fn.write_text(data=json_list) file_asset = dp.File(file=fn) json_asset = dp.File(data=json_list, is_json=True) plot_asset = dp.Plot(data=plot) list_asset = dp.File(data=lis, is_json=True) df_asset = dp.Table(df=df, caption="Our Dataframe") dp_report = api.Report(m, file_asset, df_asset, json_asset, plot_asset, list_asset) dp_report.publish(name=name, headline=headline) with deletable(dp_report): # are the fields ok assert dp_report.headline == headline assert len(dp_report.top_block.blocks) == 6
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, ), )
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, )
go.Scatter( x=[0, 1, 2, 3, 4, 5], y=[1.5, 1, 1.3, 0.7, 0.8, 0.9] )) fig.add_trace( go.Bar( x=[0, 1, 2, 3, 4, 5], y=[1, 0.5, 0.7, -1.2, 0.3, 0.4] )) plotly_asset = dp.Plot(data=fig) # Markdown md_block = dp.Markdown(text="# Test markdown block \n Test **content**") # In-line JSON list_asset = dp.File(data=lis, is_json=True) # Downloadable file file_asset = dp.File(data=lis) # In-line image img_asset = dp.File(file=Path("./datapane-logo.png")) # Vega vega_asset = dp.Plot(data=alt.Chart(gen_df()).mark_line().encode(x="x", y="y")) # Table df_asset = dp.DataTable(df, can_pivot=False) # Pivot table pv_asset = dp.DataTable(gen_df(10), can_pivot=True)
most_positive_sites[:-2] + [", and ".join(most_positive_sites[-2:])]) response_rate = "80%" nps_score = "52%" report = dp.Report( dp.Text(executive_summary_pt1).format( # nps_score=nps_score, # responce_rate=response_rate, most_positive=most_positive_answers, most_negative=most_negative_answers, ), dp.Text("#### Trend Charts"), dp.Group( dp.File(file="images/largest_since_fy18_plot.png"), dp.File(file="images/smallest_since_fy18_plot.png"), columns=2, ), dp.Group( dp.File(file="images/largest_since_fy20_plot.png"), dp.File(file="images/smallest_since_fy20_plot.png"), columns=2, ), dp.Text(file="text/executive_summary_pt2.md").format( ct_site_plot=dp.File(file="images/ct_site_section_plot.png"), academic_affairs_plot=dp.File( file="images/academic_affairs_section_plot.png"), student_life_plot=dp.File(file="images/student_life_section_plot.png"), college_prep_plot=dp.File(file="images/college_prep_section_plot.png"), coaching_plot=dp.File(