js脚本无法在Dash应用中加载-提取_reload-hash

时间:2019-05-21 15:56:07

标签: javascript plotly-dash

在Dash应用程序中加载JS脚本时遇到一些麻烦

我的应用组织为

assets
    -- custom-scripts.js
    -- style.css
app.py

所以,我的app.py文件是:

import dash
import dash_html_components as html

external_stylesheets = [
    {
        'href': 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css',
        'rel': 'stylesheet',
        'integrity': 'sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4',
        'crossorigin': 'anonymous'
    }
]

external_scripts = [
    {
        'src': 'https://use.fontawesome.com/releases/v5.0.13/js/solid.js',
        'integrity': 'sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ',
        'crossorigin': 'anonymous'
    },
    {
        'src': 'https://use.fontawesome.com/releases/v5.0.13/js/fontawesome.js',
        'integrity': 'sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY',
        'crossorigin': 'anonymous'
    },
    {
        'src': 'https://code.jquery.com/jquery-3.3.1.slim.min.js',
        'integrity': 'sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo',
        'crossorigin': 'anonymous'
    },
    {
        'src': 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js',
        'integrity': 'sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ',
        'crossorigin': 'anonymous'
    },
    {
        'src': 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js',
        'integrity': 'sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm',
        'crossorigin': 'anonymous'
    }
]


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

app.layout = html.Div(
    className='wrapper',
    children=[
        # <!-- Sidebar -->
        html.Nav(
            id='sidebar',
            children=[
                html.Div(
                    children=html.H3('Name of the App'),
                    className='sidebar-header'
                ),
                html.Ul(
                    className='list-unstyled components',
                    children=[
                        html.P('Navigation'),
                        html.Li(
                            className='active',
                            children=[
                                html.A(
                                    'Home',
                                    href='#homeSubmenu',
                                    className = 'dropdown-toggle',
                                    **{'aria-expanded': 'false', 'data-toggle': 'collapse'}
                                ),
                                html.Ul(
                                    className='collapse list-unstyled',
                                    id='homeSubmenu',
                                    children=[
                                        html.Li(
                                            html.A(
                                                'Home 1',
                                                href='#'
                                            )
                                        ),
                                        html.Li(
                                            html.A(
                                                'Home 2',
                                                href='#'
                                            )
                                        ),
                                        html.Li(
                                            html.A(
                                                'Home 3',
                                                href='#'
                                            )
                                        ),
                                    ]
                                )
                            ]
                        ),
                        html.Li(
                            children=[
                                html.A(
                                    'About',
                                    href='#'
                                )
                            ]
                        ),
                        html.Li(
                            children=[
                                html.A(
                                    'Contact',
                                    href='#'
                                )
                            ]
                        )
                    ]
                )
            ]

        ),

         # <!-- Page Content -->
         html.Div(
             id='content',
             children=[
                 html.Nav(
                     className = 'navbar navbar-expand-lg navbar-light bg-light',
                     children=[
                         html.Div(
                             className = 'container-fluid',
                             children = [
                                 html.Button(
                                     type = 'button',
                                     id = 'sidebarCollapse',
                                     className = 'btn btn-info',
                                     children = [
                                         html.I(className='fas fa-align-left'),
                                         html.Span('Toggle Sidebar')
                                     ]
                                 )
                             ]
                         )
                     ]
                 )
             ]
         ),

        )
    ]
)

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

我的custom-scripts.js文件是

        $(document).ready(function () {
            $('#sidebarCollapse').on('click', function () {
                $('#sidebar').toggleClass('active');
            });
        });

CSS文件与https://bootstrapious.com/tutorial/sidebar/style4.css

相同

当我加载我的应用程序时,有时会出现“ Toggle Sidebar”按钮,但有时却不起作用,我也不知道这取决于哪个。

有时候可以用,但我只能刷新页面,而不能再用了。

enter image description here

停止应用后,我会在控制台中看到以下内容: enter image description here

所以我认为我在获取_reload-hash时遇到问题

0 个答案:

没有答案