DASH:为什么我的DASH应用程序在通过命令提示符运行时无法运行?

2022-04-19 00:00:00 python plotly plotly-dash

问题描述

我从网上下载了一个简单的DASH PARTLY示例,它在我的电脑上运行正常。我已经在我的Windows10 PC上安装了Anconda、Python3.7、Dash和Ploly。我在保存这段代码的目录中使用命令提示符运行它。我获得本地主机地址,当我在浏览器中粘贴并运行此地址时,我会获得所有图表。

在安装了anaconda、python3.7、dash和ploly之后,当我在其他Windows10PC上运行相同的代码时,什么都不起作用。当我使用pythonapp.py通过命令行调用代码时,它什么也不做。它只是转到命令提示符下一行。我真的很困惑。我也在使用app.run_server(DEBUG=True)运行它,但什么也没有发生。

在第二种情况下,我无法发布错误消息或任何其他详细信息,因为我没有收到任何信息,这使得调试更加困难。

import json

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

styles = {
    'pre': {
        'border': 'thin lightgrey solid',
        'overflowX': 'scroll'
    }
}

df = pd.DataFrame({
    "x": [1,2,1,2],
    "y": [1,2,3,4],
    "customdata": [1,2,3,4],
    "fruit": ["apple", "apple", "orange", "orange"]
})

fig = px.scatter(df, x="x", y="y", color="fruit", custom_data=["customdata"])

fig.update_layout(clickmode='event+select')

fig.update_traces(marker_size=20)

app.layout = html.Div([
    dcc.Graph(
        id='basic-interactions',
        figure=fig
    ),

    html.Div(className='row', children=[
        html.Div([
            dcc.Markdown("""
                **Hover Data**

                Mouse over values in the graph.
            """),
            html.Pre(id='hover-data', style=styles['pre'])
        ], className='three columns'),

        html.Div([
            dcc.Markdown("""
                **Click Data**

                Click on points in the graph.
            """),
            html.Pre(id='click-data', style=styles['pre']),
        ], className='three columns'),

        html.Div([
            dcc.Markdown("""
                **Selection Data**

                Choose the lasso or rectangle tool in the graph's menu
                bar and then select points in the graph.

                Note that if `layout.clickmode = 'event+select'`, selection data also 
                accumulates (or un-accumulates) selected data if you hold down the shift
                button while clicking.
            """),
            html.Pre(id='selected-data', style=styles['pre']),
        ], className='three columns'),

        html.Div([
            dcc.Markdown("""
                **Zoom and Relayout Data**

                Click and drag on the graph to zoom or click on the zoom
                buttons in the graph's menu bar.
                Clicking on legend items will also fire
                this event.
            """),
            html.Pre(id='relayout-data', style=styles['pre']),
        ], className='three columns')
    ])
])


@app.callback(
    Output('hover-data', 'children'),
    [Input('basic-interactions', 'hoverData')])
def display_hover_data(hoverData):
    return json.dumps(hoverData, indent=2)


@app.callback(
    Output('click-data', 'children'),
    [Input('basic-interactions', 'clickData')])
def display_click_data(clickData):
    return json.dumps(clickData, indent=2)


@app.callback(
    Output('selected-data', 'children'),
    [Input('basic-interactions', 'selectedData')])
def display_selected_data(selectedData):
    return json.dumps(selectedData, indent=2)


@app.callback(
    Output('relayout-data', 'children'),
    [Input('basic-interactions', 'relayoutData')])
def display_relayout_data(relayoutData):
    return json.dumps(relayoutData, indent=2)


if __name__ == '__main__':
    app.run_server(debug=True)


解决方案

我无法对您的原始帖子发表评论,因为我的代表点低于50,但您能在命令提示符中显示您键入的内容吗?这很令人沮丧(我也为此感到内疚),但您输入的地址正确吗?

请随意删除此内容,或者如果我们得到解决方案,我可以输入更好的答案。

相关文章