<small id='G0lB6'></small><noframes id='G0lB6'>

    <tfoot id='G0lB6'></tfoot>
  1. <legend id='G0lB6'><style id='G0lB6'><dir id='G0lB6'><q id='G0lB6'></q></dir></style></legend>

      <bdo id='G0lB6'></bdo><ul id='G0lB6'></ul>
  2. <i id='G0lB6'><tr id='G0lB6'><dt id='G0lB6'><q id='G0lB6'><span id='G0lB6'><b id='G0lB6'><form id='G0lB6'><ins id='G0lB6'></ins><ul id='G0lB6'></ul><sub id='G0lB6'></sub></form><legend id='G0lB6'></legend><bdo id='G0lB6'><pre id='G0lB6'><center id='G0lB6'></center></pre></bdo></b><th id='G0lB6'></th></span></q></dt></tr></i><div id='G0lB6'><tfoot id='G0lB6'></tfoot><dl id='G0lB6'><fieldset id='G0lB6'></fieldset></dl></div>

      如何不在 Dash 中显示默认的 dcc.graph 模板?

      时间:2023-09-28

        <tbody id='Km8ZA'></tbody>

      <tfoot id='Km8ZA'></tfoot>
    1. <i id='Km8ZA'><tr id='Km8ZA'><dt id='Km8ZA'><q id='Km8ZA'><span id='Km8ZA'><b id='Km8ZA'><form id='Km8ZA'><ins id='Km8ZA'></ins><ul id='Km8ZA'></ul><sub id='Km8ZA'></sub></form><legend id='Km8ZA'></legend><bdo id='Km8ZA'><pre id='Km8ZA'><center id='Km8ZA'></center></pre></bdo></b><th id='Km8ZA'></th></span></q></dt></tr></i><div id='Km8ZA'><tfoot id='Km8ZA'></tfoot><dl id='Km8ZA'><fieldset id='Km8ZA'></fieldset></dl></div>

        <legend id='Km8ZA'><style id='Km8ZA'><dir id='Km8ZA'><q id='Km8ZA'></q></dir></style></legend>
        • <bdo id='Km8ZA'></bdo><ul id='Km8ZA'></ul>

            <small id='Km8ZA'></small><noframes id='Km8ZA'>

                本文介绍了如何不在 Dash 中显示默认的 dcc.graph 模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我试图在应用程序运行时不显示默认的 dcc.graph.我只想在应用运行时显示我的图表

                这是我的代码,

                应用布局

                dbc.Row([dbc.Col([dcc.Graph(id='datatable-upload-graph', responsive=True, style={显示":阻止"})], xs=10, sm=8, md=5, lg=6, xl=5)])

                回调和方法

                @app.callback(输出('数据表上传图','图'),输入('容器数据表','数据'))def display_gantt(container_datatable):df = pd.DataFrame(container_datatable)df['开始日期'] = pd.to_datetime(df['开始日期'], errors='强制')df['End Date'] = pd.to_datetime(df['End Date'], errors='coerce')fig = px.timeline(df, x_start="开始日期", x_end="结束日期", y="项目名称", color="状态")fig.update_yaxes(autorange="reversed")如果 container_datatable 为无:返回 []别的:返回无花果app.config['suppress_callback_exceptions'] = True如果 __name__ == '__main__':app.run_server(debug=True, use_reloader=False)

                解决方案

                本质:

                只要确保不要未指定 dcc.Graphfigure 属性,而是像这样:

                dcc.Graph(id='datatable-upload-graph', figure = blank_figure())

                其中 blank_figure() 是一个图形,它不仅像默认版本一样为空,而且去除了所有可见特征.


                详情:

                在您的应用布局中,您已经设置了

                使用 figure = blank_figure() 应用将如下所示:

                当模拟结束时,应用程序将如下所示:

                现在您可以轻松查看使用不同模板的图形的外观,例如 'plotly_dark':

                只需在注释掉这两行之间切换,即可查看下面完整代码段中的效果.

                dcc.Graph(id="graph", figure = blank_fig())# dcc.Graph(id="graph")

                完整代码:

                将 numpy 导入为 np将熊猫导入为 pd将 plotly.express 导入为 px导入 plotly.graph_objects导入破折号将 dash_core_components 导入为 dcc将 dash_html_components 导入为 html从 jupyter_dash 导入 JupyterDash从 dash.dependencies 导入输入、输出模板= ['plotly','seaborn','simple_white','ggplot2','plotly_white'、'plotly_dark'、'演示文稿'、'xgridoff'、'ygridoff','gridon','无']定义空白图():fig = go.Figure(go.Scatter(x=[], y = []))fig.update_layout(模板=无)fig.update_xaxes(showgrid = False,showticklabels = False,zeroline=False)fig.update_yaxes(showgrid = False,showticklabels = False,zeroline=False)返回无花果# startfig = blank_fig()# 破折号应用程序 = JupyterDash(__name__)app.layout = html.Div([dcc.RadioItems(id='template_radio',options=[{'label': k, 'value': k} for k in templates],值=模板[0]),html.Hr(),html.Div(id='display_templates'),dcc.Graph(id="graph", figure = blank_fig())# dcc.Graph(id="graph")])# 用选定的模板制作一个图形@app.callback(输出('graph', 'figure'),[输入('template_radio','value')])def make_graph(模板):np.random.seed(1)开始 = 2021ncols = 50nrows = 100cols = [str(i) for i in np.arange(start, start+ncols)]df = pd.DataFrame(np.random.randint(-2,3, (nrows,ncols)), columns = cols).cumsum()df.iloc[0] = 0# 数字fig = px.line(df, x=df.index, y=cols)fig.update_layout(模板 = 模板)返回无花果app.run_server(mode='inline', 端口 = 8070, dev_tools_ui=True,dev_tools_hot_reload =真,线程=真)

                I am trying not the show the defult dcc.graph when the app runs. I just want to show my graph when app runs

                Here is my code,

                App layout

                dbc.Row([
                    dbc.Col([
                        dcc.Graph(id='datatable-upload-graph', responsive=True, style={
                            'display': 'block'
                        })
                    ], xs=10, sm=8, md=5, lg=6, xl=5)
                ])
                

                Callbacks and methods

                @app.callback(
                Output('datatable-upload-graph', 'figure'),
                Input('container-datatable', 'data')
                )
                def display_gantt(container_datatable):
                    df = pd.DataFrame(container_datatable)
                
                    df['Start Date'] = pd.to_datetime(df['Start Date'], errors='coerce')
                    df['End Date'] = pd.to_datetime(df['End Date'], errors='coerce')
                
                    fig = px.timeline(df, x_start="Start Date", x_end="End Date", y="Project Name", color="Status")
                    fig.update_yaxes(autorange="reversed")
                
                    if container_datatable is None:
                        return []
                    else:
                        return fig
                
                app.config['suppress_callback_exceptions'] = True
                if __name__ == '__main__':
                    app.run_server(debug=True, use_reloader=False)
                

                解决方案

                The essence:

                Just make sure to not leave the figure attribute of dcc.Graph unspecified, but rather, for example, like this:

                dcc.Graph(id='datatable-upload-graph', figure = blank_figure())
                

                Where blank_figure() is a figure that is not only empty like in the default version, but stripped of all visible features.


                The details:

                In your app layout you've set up your dcc.Graph as:

                dcc.Graph(id='datatable-upload-graph', responsive=True, style={
                    'display': 'block'
                })
                

                What you're missing here is a specification for the figure attribute. Your app will work perfectly fine without it, but you will end up with that empty figure until you've managed to populate the figure object through one of your callbacks. And for longer loading times the empty figure will become visible.

                But you can remedy this by specifying a completely blank figure like:

                dcc.Graph(id='datatable-upload-graph', figure = blank_figure())
                

                where blank_figure() is this:

                def blank_fig():
                    fig = go.Figure(go.Scatter(x=[], y = []))
                    fig.update_layout(template = None)
                    fig.update_xaxes(showgrid = False, showticklabels = False, zeroline=False)
                    fig.update_yaxes(showgrid = False, showticklabels = False, zeroline=False)
                    
                    return fig
                

                The code snippet below will let you test this with a random data sample. The app itself is pretty neat as well (in all modesty). Nothing too fancy, but it will let you check out some templates available for your figures through fig.update_layout(template = <template>)

                Without including figure = blank_figure() in dcc.Graph, the app will look like this for a brief moment:

                And with figure = blank_figure() the app will look like this:

                And when the simulations have come to an end the app will look like this:

                And now you can easily take a look at how the figure will look like using the different templates, like 'plotly_dark':

                Just switch between commenting out these two lines to see the effects in the complete snippet below.

                dcc.Graph(id="graph", figure = blank_fig())
                # dcc.Graph(id="graph")
                

                Complete code:

                import numpy as np
                import pandas as pd
                import plotly.express as px
                import plotly.graph_objects as go
                
                import dash
                import dash_core_components as dcc
                import dash_html_components as html
                from jupyter_dash import JupyterDash
                from dash.dependencies import Input, Output
                
                
                templates = ['plotly', 'seaborn', 'simple_white', 'ggplot2',
                             'plotly_white', 'plotly_dark', 'presentation', 'xgridoff',
                             'ygridoff', 'gridon', 'none']
                
                def blank_fig():
                    fig = go.Figure(go.Scatter(x=[], y = []))
                    fig.update_layout(template = None)
                    fig.update_xaxes(showgrid = False, showticklabels = False, zeroline=False)
                    fig.update_yaxes(showgrid = False, showticklabels = False, zeroline=False)
                    
                    return fig
                
                # startfig = blank_fig()
                
                # Dash
                app = JupyterDash(__name__)
                app.layout = html.Div([
                                        dcc.RadioItems(
                                            id='template_radio',
                                            options=[{'label': k, 'value': k} for k in templates],
                                            value=templates[0]
                                        ),
                
                                        html.Hr(),
                                        html.Div(id='display_templates'),
                                        dcc.Graph(id="graph", figure = blank_fig())
                #                         dcc.Graph(id="graph")
                
                ])
                
                # Make a figure with selected template
                @app.callback(Output('graph', 'figure'),
                             [Input('template_radio', 'value')])
                def make_graph(template):
                    np.random.seed(1)
                    start = 2021
                    ncols = 50
                    nrows = 100
                    cols = [str(i) for i in np.arange(start, start+ncols)]
                    df = pd.DataFrame(np.random.randint(-2,3, (nrows,ncols)), columns = cols).cumsum()
                    df.iloc[0] = 0
                
                    # figure
                    fig = px.line(df, x=df.index, y=cols)
                    fig.update_layout(template = template)
                
                    return fig
                
                app.run_server(mode='inline', port = 8070, dev_tools_ui=True,
                          dev_tools_hot_reload =True, threaded=True)
                

                这篇关于如何不在 Dash 中显示默认的 dcc.graph 模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Plotly Scattermapbox:有没有办法在标记上方和下方包含一些文本? 下一篇:如何调整我的 Plotly 条高度并仅显示条的边缘(在子图中)?

                相关文章

                1. <tfoot id='Q4OUy'></tfoot>

                    <legend id='Q4OUy'><style id='Q4OUy'><dir id='Q4OUy'><q id='Q4OUy'></q></dir></style></legend>

                    <small id='Q4OUy'></small><noframes id='Q4OUy'>

                      <bdo id='Q4OUy'></bdo><ul id='Q4OUy'></ul>

                    <i id='Q4OUy'><tr id='Q4OUy'><dt id='Q4OUy'><q id='Q4OUy'><span id='Q4OUy'><b id='Q4OUy'><form id='Q4OUy'><ins id='Q4OUy'></ins><ul id='Q4OUy'></ul><sub id='Q4OUy'></sub></form><legend id='Q4OUy'></legend><bdo id='Q4OUy'><pre id='Q4OUy'><center id='Q4OUy'></center></pre></bdo></b><th id='Q4OUy'></th></span></q></dt></tr></i><div id='Q4OUy'><tfoot id='Q4OUy'></tfoot><dl id='Q4OUy'><fieldset id='Q4OUy'></fieldset></dl></div>