Python数据分析 之 制作酷炫的可视化大屏,特简单,2024年最新牛逼

@cache.memoize(timeout=3590), 可选择设置缓存, 我没使用

def get_df():

“”“获取当日最新的文章数据”“”

df = pd.read_sql(today, con=engine)

df[‘date_day’] = df[‘date’].apply(lambda x: x.split(’ ')[0]).astype(‘datetime64[ns]’)

df[‘date_month’] = df[‘date’].apply(lambda x: x[:7].split(‘-’)[0] + “年” + x[:7].split(‘-’)[-1] + “月”)

df[‘weekday’] = df[‘date_day’].dt.weekday

df[‘year’] = df[‘date_day’].dt.year

df[‘month’] = df[‘date_day’].dt.month

df[‘week’] = df[‘date_day’].dt.isocalendar().week

return df

导航栏的图片及标题

head = html.Div([

html.Div(html.Img(src=‘./assets/img.jpg’, height=“100%”), style={“float”: “left”, “height”: “90%”, “margin-top”: “5px”, “border-radius”: “50%”, “overflow”: “hidden”}),

html.Span(“{}博客的Dashboard”.format(info[‘author_name’][0]), className=‘app-title’),

], className=“row header”)

第一列的文字及数字信息

columns = info.columns[3:]

col_name = [‘文章数’, ‘关注数’, ‘喜欢数’, ‘评论数’, ‘等级’, ‘访问数’, ‘积分’, ‘排名’]

row1 = html.Div([

indicator(col_name[i], col) for i, col in enumerate(columns)

], className=‘row’)

第二列

row2 = html.Div([

html.Div([

html.P(“每月文章写作情况”),

dcc.Graph(id=“bar”, style={“height”: “90%”, “width”: “98%”}, config=dict(displayModeBar=False),)

], className=“col-4 chart_div”,),

html.Div([

html.P(“各类型文章占比情况”),

dcc.Graph(id=“pie”, style={“height”: “90%”, “width”: “98%”}, config=dict(displayModeBar=False),)

], className=“col-4 chart_div”),

html.Div([

html.P(“各类型文章阅读情况”),

dcc.Graph(id=“mix”, style={“height”: “90%”, “width”: “98%”}, config=dict(displayModeBar=False),)

], className=“col-4 chart_div”,)

], className=‘row’)

年数统计, 我的是2019 2020 2021

years = get_df()[‘year’].unique()

select_list = [‘每月文章’, ‘类型占比’, ‘类型阅读量’, ‘每日情况’]

两个可交互的下拉选项

dropDowm1 = html.Div([

html.Div([

dcc.Dropdown(id=‘dropdown1’,

options=[{‘label’: ‘{}年’.format(year), ‘value’: year} for year in years],

value=years[1], style={‘width’: ‘40%’})

], className=‘col-6’, style={‘padding’: ‘2px’, ‘margin’: ‘0px 5px 0px’}),

html.Div([

dcc.Dropdown(id=‘dropdown2’,

options=[{‘label’: select_list[i], ‘value’: item} for i, item in enumerate([‘bar’, ‘pie’, ‘mix’, ‘heatmap’])],

value=‘heatmap’, style={‘width’: ‘40%’})

], className=‘col-6’, style={‘padding’: ‘2px’, ‘margin’: ‘0px 5px 0px’})

], className=‘row’)

第三列

row3 = html.Div([

html.Div([

html.P(“每日写作情况”),

dcc.Graph(id=“heatmap”, style={“height”: “90%”, “width”: “98%”}, config=dict(displayModeBar=False),)

], className=“col-6 chart_div”,),

html.Div([

html.P(“文章列表”),

html.Div(get_news_table(get_df()), id=‘click-data’),

], classNa

  • 11
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值