繁体   English   中英

有没有办法使用 python 将 html 文件(情节)写入 azure 存储 blob?

[英]Is there a way to write an html file (plotly) to azure storage blob with python?

我一直试图找到一种方法将 html 文件上传到 python 中的 azure 存储 blob。 我尝试创建一个临时文件夹,保存 html 文件并从那里上传。 我也试过直接使用我的 output 绑定来设置它(这不起作用)。

我已经成功上传了 JPEG,但我需要 HTML 文件作为用户动态文件(它是使用图形 / plotly 库创建的)。

    def main(mytimer: func.TimerRequest,outputblob: func.Out[bytes],inputblob: bytes,mypictureblob: func.Out[func.InputStream]): 



    def return_graph(final_difference):
    final_difference = final_difference
    fig = go.Figure()
    fig.add_trace(go.Scatter(y=final_difference['Expected Supply'],x = final_difference.index,hoverinfo='x+y',
                            mode = 'lines',
                            fill='tozeroy'))

    fig.update_layout(
        
        title="24 Month Supply and Demand - Daily Peak Hour",
        xaxis_title="Date",
        yaxis_title="MW Surplus",
        legend_title="",
        font=dict(
            family="Courier New, monospace",
            size=15,
            color="green"
        ))

    fig.update_layout(
        title={
            'text': "24 Month Supply and Demand - Daily Peak Hour",
            'y':0.9,
            'x':0.5,
            'xanchor': 'center',
            'yanchor': 'top'})


    dir_path = tempfile.gettempdir()
    asf = fig.write_html(file = dir_path  + '/ss.html')
    # This is just the naïve method to just hopefully cram it in the azure storage 
    #mypictureblob.set(asf)
    image_stream = BytesIO()
    asf.savefig(image_stream)
    image_stream.seek(0)
    with BytesIO() as input_blob:
        mypictureblob.set(image_stream)

缺少代码,但到目前为止它仍然有效。 这是 100% 的输入/输出问题,或者我试图错误地找到我创建的临时文件夹。

这是我的 JSON function 文件如下:

在此处输入图像描述

我想通了,以防有人遇到这个寻找解决方案。

    def return_graph(final_difference):
    final_difference = final_difference
    fig = go.Figure()
    fig.add_trace(go.Scatter(y=final_difference['Expected Supply'],x = final_difference.index,hoverinfo='x+y',
                            mode = 'lines',
                            fill='tozeroy'))

    fig.update_layout(
        
        title="24 Month Supply and Demand - Daily Peak Hour",
        xaxis_title="Date",
        yaxis_title="MW Surplus",
        legend_title="",
        font=dict(
            family="Courier New, monospace",
            size=15,
            color="green"
        ))

    fig.update_layout(
        title={
            'text': "24 Month Supply and Demand - Daily Peak Hour",
            'y':0.9,
            'x':0.5,
            'xanchor': 'center',
            'yanchor': 'top'})
    tempFilePath = tempfile.gettempdir()
    fp = tempfile.NamedTemporaryFile()
    
    fig_div = fig.to_html()
    mypictureblob.set(fig_div)

区别在于 fig.to_html 与 fig.write_html。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM