admin管理员组文章数量:1122846
I have this route for my fastapi app taking care of displaying favicon.ico
:
@app.get('/favicon.ico', include_in_schema=False, response_class=FileResponse)
async def favicon():
""" favicon - do not show up on plotly graphs """
return FileResponse("static/favicon.png")
Works fine for anything returning HTMLResponse
but not the one rendering a plotly.graph_objects
If I remove the above route I see this in the log when rendering:
127.0.0.1:59780 - "GET /favicon.ico HTTP/1.1" 404
But nothing when it is present.
there is no mention of favicon
in .html
A summary of the plotly go.Figure
:
import plotly.graph_objects as go
:
fig = go.Figure(
data = [
go.Bar(name="Success", x=data['xpos'], y=data['success_count'], marker={'color':'green'}, text=data['success_tests'], textposition='none'),
go.Bar(name="Failed", x=data['xpos'], y=data['failed_count'], marker={'color':'red'}, text=data['failed_tests'], textposition='none')
],
layout = go.Layout(barmode='stack', xaxis={'type': 'category'})
)
for i,px in enumerate(data['xpos']):
nice = timegraph['nice'][i]
url = data['urls'][i]
fig.add_annotation(x=px, xshift=10, y=0, yshift=80, text=f"<a href=\"{url}\" alt=_blank>{px} - {nice}</a>", textangle=270, bgcolor="#FFFFFF", opacity=0.5)
fig.add_trace(
go.Scatter(
x=data['xpos'],
y=timegraph['ygrid'],
yaxis="y2",
name="Total Testrun Time",
marker={'color': 'gray', 'size': 15},
text=timegraph['nice'],
mode='markers',
zorder=100,
)
)
fig.update_layout(
plot_bgcolor=plot_bgcolor,
paper_bgcolor=plot_bgcolor,
yaxis={
'title':{'text':"Number of Tests"},
'side':"left",
'color': 'green',
'gridcolor': 'green'
},
yaxis2={
'title':{'text':"Total Testrun Time(s)"},
'side': "right",
'overlaying': "y",
'color': 'gray',
'showgrid': False,
'tickformat': '%M:%S'
},
title=f"{desc}<br>{sr}</br>(rendertime:{time.time()-starttime:.2f}sec)",
)
fig.update_xaxes(showticklabels=False)
#log.debug(f"fig:{fig}")
return fig.to_html(config={'displayModeBar': False})
I have this route for my fastapi app taking care of displaying favicon.ico
:
@app.get('/favicon.ico', include_in_schema=False, response_class=FileResponse)
async def favicon():
""" favicon - do not show up on plotly graphs """
return FileResponse("static/favicon.png")
Works fine for anything returning HTMLResponse
but not the one rendering a plotly.graph_objects
If I remove the above route I see this in the log when rendering:
127.0.0.1:59780 - "GET /favicon.ico HTTP/1.1" 404
But nothing when it is present.
there is no mention of favicon
in https://plotly.com/python-api-reference/genindex.html
A summary of the plotly go.Figure
:
import plotly.graph_objects as go
:
fig = go.Figure(
data = [
go.Bar(name="Success", x=data['xpos'], y=data['success_count'], marker={'color':'green'}, text=data['success_tests'], textposition='none'),
go.Bar(name="Failed", x=data['xpos'], y=data['failed_count'], marker={'color':'red'}, text=data['failed_tests'], textposition='none')
],
layout = go.Layout(barmode='stack', xaxis={'type': 'category'})
)
for i,px in enumerate(data['xpos']):
nice = timegraph['nice'][i]
url = data['urls'][i]
fig.add_annotation(x=px, xshift=10, y=0, yshift=80, text=f"<a href=\"{url}\" alt=_blank>{px} - {nice}</a>", textangle=270, bgcolor="#FFFFFF", opacity=0.5)
fig.add_trace(
go.Scatter(
x=data['xpos'],
y=timegraph['ygrid'],
yaxis="y2",
name="Total Testrun Time",
marker={'color': 'gray', 'size': 15},
text=timegraph['nice'],
mode='markers',
zorder=100,
)
)
fig.update_layout(
plot_bgcolor=plot_bgcolor,
paper_bgcolor=plot_bgcolor,
yaxis={
'title':{'text':"Number of Tests"},
'side':"left",
'color': 'green',
'gridcolor': 'green'
},
yaxis2={
'title':{'text':"Total Testrun Time(s)"},
'side': "right",
'overlaying': "y",
'color': 'gray',
'showgrid': False,
'tickformat': '%M:%S'
},
title=f"{desc}<br>{sr}</br>(rendertime:{time.time()-starttime:.2f}sec)",
)
fig.update_xaxes(showticklabels=False)
#log.debug(f"fig:{fig}")
return fig.to_html(config={'displayModeBar': False})
Share
Improve this question
asked yesterday
MortenBMortenB
3,4893 gold badges44 silver badges49 bronze badges
1
|
1 Answer
Reset to default 1Thanks to @EricLavault
I changed the return to:
return fig.to_html(config={'displayModeBar': False}, full_html=False)
It shows the favicon.ico
, but there is no <html><header></header><body></body></html>
structure.
You can render it via file as described here: https://plotly.com/python/interactive-html-export/
本文标签: python plotly add favicon to FigureStack Overflow
版权声明:本文标题:python plotly add favicon to Figure - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736280783a1926111.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<div>
(instead of the whole html document) usingfig.to_html(full_html=False)
, and wrap that div in a custom html page template where you can set your favicon etc. – EricLavault Commented yesterday