Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 破折号中的多页应用程序-在其他页面中无法识别下拉列表值_Javascript_Python_Html_Css_Plotly Dash - Fatal编程技术网

Javascript 破折号中的多页应用程序-在其他页面中无法识别下拉列表值

Javascript 破折号中的多页应用程序-在其他页面中无法识别下拉列表值,javascript,python,html,css,plotly-dash,Javascript,Python,Html,Css,Plotly Dash,当我移动到另一个页面时,下拉值不会被拉入并显示 有人能帮忙吗 我试着阅读联机dash文档()和本文(),但没有成功 import flask import dash from dash.dependencies import Input, Output, State import dash_core_components as dcc import dash_html_components as html import dash_auth external_stylesheets = ['h

当我移动到另一个页面时,下拉值不会被拉入并显示

有人能帮忙吗

我试着阅读联机dash文档()和本文(),但没有成功

import flask
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import dash_auth


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.config['suppress_callback_exceptions']=True

url_bar_and_content_div = html.Div([
    dcc.Location(id='url', refresh=False),
    html.Div(id='page-content')
])


index_page = html.Div([
dcc.Link('Go to Questionnaire', href='/questionnaire'),
])


intro_page_layout = html.Div([
    dcc.Store(id='memory-ouput', storage_type='memory'),
    html.Div([
                html.Div(

                    html.H6("""Select your current industry""",
                            style={'margin-right': '2em'})
            ),

            dcc.Dropdown(
                id='business_area_dropdown',
                options=[
                    {'label': 'Academia', 'value': 'academia'},
                    {'label': 'Energy', 'value': 'energy'},
                    {'label': 'Research', 'value': 'research'}
                ],
                placeholder="Select Business Area",
                style=dict(
                    width='40%',
                    verticalAlign="middle"
                )
            )],
        style=dict(display='flex')
    ),

    html.Div([
            html.Div(
                    html.H6("""Are you happy where you are?""",
                            style={'margin-right': '2em'})
            ),

            dcc.Dropdown(
                id='search_preference',
                options=[
                    {'label': 'Yes', 'value': 'yes'},
                    {'label': 'No', 'value': 'no'}
                ],
                placeholder="Select Answer",
                style=dict(
                    width='40%',
                    display='inline-block',
                    verticalAlign="middle"
                )
            )],

        style=dict(display='flex')
    ), 

    dcc.Link(
    html.Button('Submit', type='submit', id='submit-button', style={'margin-bottom': '5em', 'width': '110px', 'height':'50px', 'padding': '10px', 'font-weight':'bold'}),
    href='/summary')

    ])


summary_page_layout = html.Div([
    html.H1('Summary Page'),
    html.Div(id='results-page-content')
    ])


def serve_layout():
    if flask.has_request_context():
        return url_bar_and_content_div
    return html.Div([
        url_bar_and_content_div,
        index_page,
        intro_page_layout,
        summary_page_layout
        ])


app.layout = serve_layout


@app.callback(Output('memory-output', 'data'), [Input('submit-button', 'n_clicks')], [State('search_preference', 'value'), State('business_area_dropdown', 'value')])
def on_click(n_clicks, input1, input2):
    if (n_clicks < 1 or n_clicks is None) and input1 is not None and input2 is not None:
        raise PreventUpdate

    return data

@app.callback(Output('results-page-content', 'children'), [Input('memory-output', 'data')], [State('search_preference', 'value'), State('business_area_dropdown', 'value')])
def on_display(data, input1, input2):
    if data is None:
        raise PreventUpdate
    return html.H3('Results are ' + input1 + ' and ' + input2)


@app.callback(Output('page-content', 'children'),[Input('url', 'pathname')])
def display_page(pathname):
    if pathname == '/questionnaire':
        return intro_page_layout
    elif pathname == '/summary':
        return summary_page_layout
    else:
        return index_page

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

导入烧瓶
导入破折号
从dash.dependencies导入输入、输出和状态
将仪表板核心组件作为dcc导入
将dash_html_组件导入为html
导入dash_auth
外部_样式表=['https://codepen.io/chriddyp/pen/bWLwgP.css']
app=dash.dash(名称,外部样式表=外部样式表)
app.config['suppress\u callback\u exceptions']=True
url\u bar\u和\u content\u div=html.div([
dcc.Location(id='url',refresh=False),
html.Div(id='page-content')
])
index\u page=html.Div([
dcc.Link('转到问卷',href='/问卷'),
])
简介页面布局=html.Div([
dcc.Store(id='memory-output',storage\u type='memory'),
html.Div([
html.Div(
H6(““选择您当前的行业””,
样式={'margin-right':'2em'})
),
dcc.下拉列表(
id='business\u area\u dropdown',
选择权=[
{'label':'academy','value':'academy'},
{'label':'Energy','value':'Energy'},
{'label':'Research','value':'Research'}
],
占位符=“选择业务区域”,
格言(
宽度='40%',
垂直对齐=“中间”
)
)],
style=dict(display='flex')
),
html.Div([
html.Div(
H6(““你在这里快乐吗?”),
样式={'margin-right':'2em'})
),
dcc.下拉列表(
id='search\u preference',
选择权=[
{'label':'Yes','value':'Yes'},
{'label':'No','value':'No'}
],
占位符=“选择答案”,
格言(
宽度='40%',
display='inline-block',
垂直对齐=“中间”
)
)],
style=dict(display='flex')
), 
链接(
按钮('Submit',type='Submit',id='Submit-Button',style={'margin-bottom':'5em','width':'110px','height':'50px',padding':'10px','font-weight':'bold'}),
href='/summary')
])
summary\u page\u layout=html.Div([
html.H1(“摘要页”),
html.Div(id='results-page-content')
])
def SERVER_布局():
如果flask.has_request_context():
返回url\u bar\u和内容\u div
返回html.Div([
url\u bar\u和\u content\u div,
索引页,
介绍页面布局,
摘要页面布局
])
app.layout=服务布局
@应用程序回调(输出('memory-Output','data'),[Input('submit-button','n_clicks')],[State('search_preference','value'),State('business_area_dropdown','value'))
单击时的def(n次单击,输入1,输入2):
如果(n_单击<1或n_单击为无)且input1不为无,input2不为无:
提出预防性更新
返回数据
@应用程序回调(输出('results-page-content','children'),[Input('memory-Output','data')],[State('search\u preference','value'),State('business\u area\u dropdown','value'))
def on_显示器(数据、输入1、输入2):
如果数据为无:
提出预防性更新
返回html.H3('结果为'+input1+'和'+input2))
@app.callback(输出('page-content','children'),[Input('url','pathname'))
def显示页面(路径名):
如果路径名=“/问卷”:
返回介绍页面布局
elif路径名=='/summary':
返回摘要页面布局
其他:
返回索引页
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
app.run_服务器(debug=True)
在摘要页面上,我应该有用户从问卷页面选择的值。奇怪的是,这些值没有显示在摘要页面上

任何帮助或指点都将不胜感激


提前感谢。

您需要将下拉列表值存储在磁盘、flask.session对象或dcc.store组件中。切换页面时,Dash不会保留其他页面的输入值。

谢谢您的帮助。这确实有助于正确看待问题。然而,我仍然遇到一些问题。。。。我会编辑上面的代码,让你看看我在做什么。干杯我仍然无法在摘要页面上显示input1和input2。。。有什么想法吗?非常感谢!不,一点也不。我最后用烧瓶而不是破折号。羞耻。。。。