将表单添加到Dash/Plotly应用程序

8
好的,我想进一步了解。我不知道是否可以使用dash实现。 我想创建一个表单(可能是来自Flask的WTForm)。 该表单应具有日期和注释/评论部分。 当有人提交表单时,它将保存到数据库中。 然后dash将读取它并在图表上显示。 我的图表看起来像这样: enter image description here 在x轴上,将使用来自FlaskForm的日期表示存储在数据库中的事件,并且当我悬停在确切的日期时,注释将显示在图表本身中。 类似于这个: enter image description here 现在,请问这是否可行?我应该使用哪些工具?这只是一个概念,但我认为对每个人都有帮助。
2个回答

1
在Plotly中,您可以使用注释来显示文本。例如:
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    y=[0, 1, 3, 2, 4, 3, 4, 6, 5]
)

trace2 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    y=[0, 4, 5, 1, 2, 2, 3, 4, 2]
)

data = [trace1, trace2]

layout = go.Layout(
    showlegend=False,
    annotations=[
        dict(
            x=2,
            y=5,
            xref='x',
            yref='y',
            text='max',
            showarrow=True,
            arrowhead=7,
            ax=0,
            ay=-40
         )
    ]
)

fig = go.Figure(data=data, layout=layout)

iplot(fig)

参考链接: https://plot.ly/python/text-and-annotations

Plot with annotation

希望这能回答你的问题。在散点图中,请参考mode='lines+markers+text'(在plotly文档的Adding Text to Data in Line and Scatter Plots部分)。保留HTML标签。

感谢您的回答,Adarsa,但我想要完全不同的东西。 - aleheca
@rafael,你有没有找到通过flask-wtf表单实现这个的方法?我知道你在plotly论坛上发布了一个使用dcc.components作为Dash表单的帖子,但我想知道你是否知道如何按照你的问题描述来做,因为我也需要同样的东西。谢谢。 - user8322222

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接