Ejemplo n.º 1
0
def gen_report_nested_blocks() -> dp.Report:
    return dp.Report(blocks=[
        dp.Blocks(
            dp.Markdown(
                text="# Test markdown block <hello/> \n Test **content**",
                id="test-id-1"),
            "Simple string Markdown",
        ),
        dp.Blocks(blocks=[
            dp.Markdown(
                text="# Test markdown block <hello/> \n Test **content**",
                id="test-id-2"),
            "Simple string Markdown",
        ]),
    ])
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def test_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.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,
                      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._top_block.blocks[0].blocks) == 6
Ejemplo n.º 4
0
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
Ejemplo n.º 5
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,
        )
Ejemplo n.º 6
0
import pandas as pd
import datapane as dp

# basic report creation, with params
df = pd.DataFrame.from_dict({"x": [4, 3, 2, 1], "y": [10.5, 20.5, 30.5, 40.5]})
blocks = [dp.Markdown(f"Dummy Markdown block - {dp.Params['p1']}"), dp.Table(df)]

# test running as main or by datapane runner
if dp.on_datapane:
    print("on datapane")
if __name__ == "__datapane__":  # same as dp.by_datapane
    print("by datapane")
    report = dp.Report(blocks=blocks)
    report.publish(name="dp_report", headline="My Report")
Ejemplo n.º 7
0
# Plotly
fig = go.Figure()
fig.add_trace(
    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)
Ejemplo n.º 8
0
"""{{ name }} script"""
import pandas as pd
import datapane as dp

# TODO - enter your code here...
df = pd.DataFrame.from_dict({"x": [4, 3, 2, 1], "y": [10.5, 20.5, 30.5, 40.5]})

# Create your datapane report components
report = dp.Report(
    dp.Markdown(f"#### **Sample** Markdown block"), dp.Table(df)
)
report.publish(name="my_report")
Ejemplo n.º 9
0
'''
DATAPANE INTERACTIVE REPORT

pip install datapane

# https://datapane.com/reports/?name=&owned_by_me=on&order=
# Remember to login
# https://towardsdatascience.com/introduction-to-datapane-a-python-library-to-build-interactive-reports-4593fd3cb9c8
'''

import pandas as pd
import altair as alt
import datapane as dp

df = pd.read_csv(
    'https://query1.finance.yahoo.com/v7/finance/download/GOOG?period2=1585222905&interval=1mo&events=history'
)

chart = alt.Chart(df).encode(x='Date:T', y='Open').mark_line().interactive()

# Once you have the df and the chart, simply use
r = dp.Report(
    dp.Markdown('My simple report'),  #add description to the report
    dp.Table(df),  #create a table
    dp.Plot(chart)  #create a chart
)

# Publish your report. Make sure to have visibility='PUBLIC' if you want to share your report
r.publish(name='stock_report', visibility='PUBLIC')
Ejemplo n.º 10
0
    dp.Markdown("""
# The Numbers on は, が,  & Co.
> ##### Contextual particle frequency in written Japanese, taking a swing at the age old question of は vs が

Particles are one of the trickiest things for Japanese learners to pick up, and this project seeks to approach the question of when and where to use some of the more common particles by looking at a little data! I took a couple corpora of Japanese text, annotated them with linguistic features, and narrowed the dataset to the particles and the words they're related to in their respective sentences. From there, I compiled the dependency and part of speech for each token as well as its syntactic head and compared particles that get commonly mixed up by Japanese learners. Alongside each comparison, I gathered some common rules of thumb used to help people distinguish which particles are appropriate in which contexts, for reference. 

---

  * [Dataset](#dataset)
    + [Full NLP for All Particles](#full-nlp-for-all-particles)
    + [Relative Frequency for All Particles](#relative-frequency-for-all-particles)
  * [Particle Comparisons](#particle-comparisons)
    + [は & が](#-----)
        * [Common Heuristics](#common-heuristics)
        * [Insights](#insights)
    + [と & も](#-----)
        * [Common Heuristics](#common-heuristics-1)
        * [Insights](#insights-1)
    + [か & や](#-----)
        * [Common Heuristics](#common-heuristics-2)
        * [Insights](#insights-2)
    + [と & って](#------)
        * [Common Heuristics](#common-heuristics-3)
        * [Insights](#insights-3)
    + [に、へ、で](#-----)
        * [Common Heuristics](#common-heuristics-4)
        * [Insights](#insights-4)
    + [ね、よ、わ、さ、な、ん](#-----------)
        * [Common Heuristics](#common-heuristics-5)
        * [Insights](#insights-5)


                 """),
Ejemplo n.º 11
0
author_rank = dp.Blob.get('author_rank', owner='khuyentran1401').download_obj()
author_count = pickle.load(open('./author_count', 'rb'))
publication_count = pickle.load(open('./publication_count', 'rb'))
publication_rank = pickle.load(open('./publication_rank', 'rb'))

# size of the data
data_size = len(author_rank)

# load parameters from input
dp.Params.load_defaults('datapane.yaml')
author = dp.Params.get('author_name', 'Khuyen Tran')
publication = dp.Params.get('publication_name')

percentile_author = 100 - (list(author_rank).index(author) +
                           1) / len(author_rank) * 100
percentile_publications = 100 - (list(publication_rank).index(publication) +
                                 1) / len(publication_rank) * 100

dp.Report(
    dp.Markdown("# Medium Visualization"),
    dp.Plot(author_count),
    dp.Markdown(f'''
   Author {author} ranks {list(author_rank).index(author)+1} out of {data_size} authors who publish most frequently on topics related to data science last year, which is
    in the {str(round(percentile_author,2))}% percentile
   '''),
    dp.Plot(publication_count),
    dp.Markdown(
        f'''Publication {publication} ranks {list(publication_rank).index(publication)+1} out of {data_size} publications which publish most frequently on topics related to data science last year, which is
    in the {str(round(percentile_publications,2))}% percentile'''),
).publish(headline='Medium Visualization', name='medium_report')
Ejemplo n.º 12
0
"""{{ name }} script"""
import pandas as pd
import datapane as dp

# TODO - enter your code here...
df = pd.DataFrame.from_dict({"x": [4, 3, 2, 1], "y": [10.5, 20.5, 30.5, 40.5]})

# Create your datapane report components
report = dp.Report(dp.Markdown(f"#### **Sample** Markdown block"),
                   dp.Table(df))
report.publish(name="my_report")