Content creation Track connections
Tags: #metrics #content-creation #connections
Author: Riddhi Deshpande

Input

Import library

1
from naas_drivers import notion
2
import naas
3
import pandas as pd
4
import plotly.express as px
Copied!

Variables

1
# Input
2
notion_token = "secret_ALstzXsSXoF9zbcUakMYE1OufXHVOkb35v1rYBTzz54"
3
notion_database = "https://www.notion.so/naas-official/37a23cbfaac5445690301dfd49f035d3?v=8ab1b2f3847d4067ac5ae19a799c7dcb"
4
5
# Output
6
output_html = "ContentCreator_No_connections.csv"
Copied!

Get data

1
# Get database object
2
db_notion = notion.connect(notion_token).database.get(notion_database)
3
4
# Get database as dataframe
5
df_notion = db_notion.df()
6
df_notion.VALUE=df_notion.VALUE.astype(float)
7
df_notion
Copied!

Model

Create a line chart and add color parameters to distinct groups

1
fig = px.line(data_frame=df_notion,
2
x='DATE',
3
y='VALUE',
4
color='GROUP')
5
6
#add button control to chart
7
fig.update_layout(
8
title=f"🚀<b> Number of Connections</b><br><span style='font-size: 13px;'></span>",
9
title_font=dict(family="Arial", size=18, color="black"),
10
legend_title=None,
11
plot_bgcolor="#ffffff",
12
width=1200,
13
height=800,
14
paper_bgcolor="white",
15
xaxis_title="Date",
16
xaxis_title_font=dict(family="Arial", size=11, color="black"),
17
yaxis_title='No. of connections',
18
yaxis_title_font=dict(family="Arial", size=11, color="black"),
19
margin_pad=10,
20
updatemenus=[
21
dict(
22
active=0,
23
buttons=list([
24
dict(
25
26
label="Both",
27
method="update",
28
args=[{"visible":[True,True]},
29
{"title": "Both"}]),
30
dict(
31
32
label="Twitter",
33
method="update",
34
args=[{"visible":[True,False]},
35
{"title": "Twitter"}]),
36
dict(
37
38
label="Linkedin",
39
method="update",
40
args=[{"visible":[False,True]},
41
{"title": "Linkedin"}])
42
]),
43
pad={"r": -80, "t": -40},
44
direction="down",
45
x=1,
46
xanchor="left",
47
y=1,
48
yanchor="top",
49
borderwidth=1,
50
bordercolor="black",
51
bgcolor=None
52
),
53
])
Copied!

Output

Save and export html

1
fig.write_html(output_html)
2
naas.asset.add(output_html, params={"inline": True})
Copied!
Copy link
Edit on GitHub