Python Plotly制作网页版表格

最近在弄一个数据小工具,最终要生成一个报表类的文件,这里记录下怎样使用plotly做的表格并转为html格式的,并用jinja2写入到html模板中去。

处理好的pandas.DateFrame数据:

    test_item  low        upper        ...       AV       TV   _%
0      charge  4600000.0    5250000.0  ...  15306    94734.9  47.49%
1   discharge  4600000.0    5250000.0  ...      0.0  37567.5  97.27%
......

python 代码:

# re = ff.create_table(report, font_colors=col).to_html() # 第一种create_table方法直接通过DataFrame格式转换,没有找到单独一行背景色的设置方法,这里不太使用。
    # re = go.Figure(data=[go.Table(
    #     header=dict(values=list(report),  #设置header表头的值
    #                 line_color='indigo',   # 颜色
    #                 fill_color='aqua',
    #                 align='center',       #对齐方式??
    #                 font=dict(color='black', size=18),  #字体
    #                 height=40),   #  高度
    #     cells=dict(values=[report['test_item'], report['low'],report['upper'], report['。。'], report['..'], report['..'], report['..'],report['_%']], #设置表格数据直接pandas获取
    #                line_color='white',
    #                fill_color=[col],#设置颜色列表,可以单独设置每行
    #                align='center',
    #                font=dict(color='black',size=13),
    #                height=30
    #                ))])
    # env = Environment(loader=FileSystemLoader("./")) 
    # template = env.get_template("temp.html")  #加载一个html的模板
    # with open('out.html', 'w+', encoding='utf-8') as f:
    #     out = template.render(report_summary=re.to_html()) #转换好的表格转换为html格式并使用jinja2模块写入
    #     f.write(out)# 

最终的结果, 不会html 所以布局有点简陋,不过是内部使用外观要求不高。

plotly 图片同理,如果表格数据过多会自动生成滑块,这对于html 转PDF时表格图片会保存不全,目前还没找到解决方法。

其他的可以参考知乎的文章:神器Jinja2,用 Python 快速生成分析报告 - 知乎  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值