Skip to content

Dash offline is enabled? #46

Closed
Closed

Description

@marugari

Can I use Dash application in offline environment?
My application can't access CDN servers and the loading page doesn't change.

#7

Activity

  1. pl77 commented on Jun 26, 2017

    @pl77

    Did you try the suggestion at the bottom of the user guide?

    https://plot.ly/dash/external-resources

    from dash import Dash
    
    app = Dash()
    
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    
  2. sbowman-mitre commented on Jun 26, 2017

    @sbowman-mitre

    Thanks for opening this, @marugari . This offline behavior is what I was wondering about too. When I try the recommended fix, I am unable to render dcc.Graph() objects. Is this expected behavior when running offline?

  3. jackluo commented on Jun 26, 2017

    @jackluo
    Contributor

    Graph() objects should be rendered offline. Can you post the errors you are having?

  4. sbowman-mitre commented on Jun 26, 2017

    @sbowman-mitre

    I don't get an error in the browser or the console running dash. I just don't get a page load. At the browser level, the HTML just renders "Loading..." and never gets passed that (waited for quite a while).

  5. pl77 commented on Jun 26, 2017

    @pl77

    I'm going from memory as I am not running dash offline now, but are you importing plot from plotly.offline?

    for example:

    from plotly.offline import download_plotlyjs, plot

    otherwise it'll still try and get the plotlyjs file from the CDN.

  6. sbowman-mitre commented on Jun 26, 2017

    @sbowman-mitre

    No, I'm not. I'm just running the first tutorial (here) which does not import anything specifically from plotly. I will try your import statement and report back.

  7. pl77 commented on Jun 26, 2017

    @pl77

    Oh that won't help then, as they are generating the figure directly in dash. The offline library I referenced only helps when the graph is being generated in a callback. Disregard my suggestion.

  8. chriddyp commented on Jun 26, 2017

    @chriddyp
    Member

    Did you try the suggestion at the bottom of the user guide?

    https://plot.ly/dash/external-resources

    from dash import Dash
    
    app = Dash()
    
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    

    That's it exactly. The dcc.Graph objects should be rendered offline too.

    Here is a standalone example that works for me with my wifi turned off:

    import dash
    import dash_core_components as dcc
    import dash_html_components as html
    
    app = dash.Dash('offline example')
    
    app.layout = html.Div([
        dcc.Graph(id='my-graph', figure={'data': [{'x': [1, 2, 3], 'y': [4, 1, 2]}]})
    ])
    
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    

    dash_offline

    @sbowman-mitre - Could you try this example and see if it works?

  9. sbowman-mitre commented on Jun 26, 2017

    @sbowman-mitre

    Yes, your example does render for me. That's good news!

    Yes, I had added those lines to my script and it did not render. Here's the entirety of my script:

    # -*- coding: utf-8 -*-
    import dash
    import dash_core_components as dcc
    import dash_html_components as html
    
    app = dash.Dash()
    
    # Force offline usage (also fails to render graph, issue #46)
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    
    app.layout = html.Div(children=[
        html.H1(children='Hello Dash'),
    
        html.Div(children='''
            Dash: A web application framework for Python.
        '''),
    
        dcc.Graph(
            id='example-graph',
            figure={
                'data': [
                    {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                    {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
                ],
                'layout': {
                    'title': 'Dash Data Visualization'
                }
            }
        )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
  10. marugari commented on Jun 27, 2017

    @marugari
    Author

    My thanks to @pl77 and @chriddyp.
    I think "Rendering dash apps offline"(https://plot.ly/dash/external-resources) should be independent.

  11. chriddyp commented on Jun 27, 2017

    @chriddyp
    Member

    Great, thanks! @sbowman-mitre - that script that you posted actually works for me OK:
    dash_offline_2

  12. sbowman-mitre commented on Jun 27, 2017

    @sbowman-mitre

    Okay, good to know. That means it's something on my end. Maybe my browser (which is up-to-date Chrome)? But, good to know the general concept should be working.

  13. chriddyp commented on Jun 27, 2017

    @chriddyp
    Member

    Hm.. I'm not sure what it could be. I have down some browser testing on these apps. If open up the Chrome Dev Tools, are there any red errors printed out?

  14. sbowman-mitre commented on Jun 27, 2017

    @sbowman-mitre

    @chriddyp : curiously, the script loads under some conditions today. Not sure what that means; I haven't rebooted in the meantime. 🤷‍♂️ When it doesn't load, here's the devtools view:
    image

  15. chriddyp commented on Jun 27, 2017

    @chriddyp
    Member

    Thanks for reporting @sbowman-mitre ! I've actually seen this before. In this case, the flask server is having trouble serving the large javascript bundle (1MB or larger) from the file system. I've only seen this happen on Windows machines and servers.

    I'm not yet sure how to resolve this or make this more stable.

  16. sbowman-mitre commented on Jun 27, 2017

    @sbowman-mitre

    Well, doesn't sound like there's much you can do except raise it up to the flask group. You can close this issue (from my perspective, anyway).

  17. chriddyp commented on Jun 29, 2017

    @chriddyp
    Member

    Thanks @sbowman-mitre ! I'll close this issue but I've opened a secondary one for this more specific problem with serving files on windows: #56

  18. prncevince commented on May 22, 2018

    @prncevince

    This was outstanding help. Thank you.

  19. highwindmx commented on Mar 17, 2019

    @highwindmx

    just a kind reminder, firefox addons such as "Decentraleyes" which block cdn tracking may a reason why your page not loading properly.

  20. added a commit that references this issue on Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions