Code Monkey home page Code Monkey logo

dash-recipes's Introduction

This repo contains all of the Dash examples that I have created while helping out the Dash community on https://community.plot.ly/c/dash.

These examples are unordered and unorganized and they might not be helpful (yet) without the context that the Dash community forum provided while creating them.

Perhaps in the future these examples will be organized into something greater. For now, if you're looking for examples, try:

dash-recipes's People

Contributors

amarvin avatar brylie avatar chriddyp avatar martinbaste avatar oriolmirosa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dash-recipes's Issues

dash-global-cache.py does not work

when I run it, error below pops up
ValueError: cannot have a multithreaded and multi process server.

I modified processes = 6 to 1. Then get the following error:
redis.exceptions.ConnectionError: Error 10061 connecting to None:6379. No connection could be made because the target machine actively refused it.

multi-threading

does this pattern apply if Dash is deployed in gunicorn with multiple threads? Or is it necessary to use the Flask-SQLAlchemy extension?

thanks!

Separate callbacks into own file

The Dash guide shows how to create a Dash app in a single file. However, the app file quickly grows to several hundred files for a moderately sized dashboard. The question of how to organize Dash apps, so that callbacks are in a separate file, has been raised several times in the Dash community forum without help. Please add a recipe for how to break down a Dash app into separate files, as can be seen in the Dash slapdash boilerplate. The Slapdash project is well-designed, but leaves a lot to be desired in terms of explaining why the files are structured in such a way and how to create a simple Dash project with that file structure.

BUG: dynamic tabs recipe

I have updated to the latest version but still receive,

File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__ return self.wsgi_app(environ, start_response) File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/Users/serlucov/anaconda/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Users/serlucov/anaconda/lib/python3.6/site-packages/dash/dash.py", line 556, in dispatch return self.callback_map[target_id]['callback'](*args) File "/Users/serlucov/anaconda/lib/python3.6/site-packages/dash/dash.py", line 513, in add_context output_value = func(*args, **kwargs) File "/Users/serlucov/WorkDocs/Markdown/Dash Master Class/dash_tabs.py", line 25, in display_content dcc.Tabs( AttributeError: module 'dash_core_components' has no attribute 'Tabs'

No graphs are shown in the dash-add-graphs-dynamically example

I copied and pasted the example verbatim because I need to dynamically create graphs for a project and was unable to figure out how to do it. However, nothing happens when I click on the 'Add graph' button. No errors appear in the console, and when inspecting the page the 'container' div has no children.

I'm using the most up-to-date version of all packages on pip as of the end of May 2018.

DangerouslySetInnerHTML script not working

below script does not work, seems outdated. From file: dash-recipes/dash-script-execution-dangerously-set-inner-html.py

import dash_dangerously_set_inner_html
import dash
import dash_html_components as html

app = dash.Dash('')

app.scripts.config.serve_locally = True

app.layout = html.Div([
dash_dangerously_set_inner_html.DangerouslySetInnerHTML('''
<script type="text/javascript">alert('test')</script>
'''),
])

if name == 'main':
app.run_server(debug=True)

Updating Table example doesn't work

Updating table code doesn't update when i enter data in the table.

These are the package versions i'm using


certifi==2018.8.24
chardet==3.0.4
Click==7.0
dash==0.28.1
dash-core-components==0.30.2
dash-html-components==0.13.2
dash-renderer==0.14.1
dash-table-experiments==0.6.0
decorator==4.3.0
Flask==1.0.2
Flask-Compress==1.4.0
idna==2.7
ipython-genutils==0.2.0
itsdangerous==0.24
Jinja2==2.10
jsonschema==2.6.0
jupyter-core==4.4.0
MarkupSafe==1.0
nbformat==4.4.0
numpy==1.15.2
pandas==0.23.4
plotly==3.3.0
pyodbc==4.0.24
python-dateutil==2.7.3
pytz==2018.5
requests==2.19.1
retrying==1.3.3
six==1.11.0
traitlets==4.3.2
urllib3==1.23
Werkzeug==0.14.1

Multiple intervals problem

Hi, im trying to execute the example "multiple-intervals.py" to see how it works and it gets me this error : "ValueError: cannot have a multithreaded and multi process server" , i dont understand why, thank you

dash-which-button.py is not working with dash 0.21.1

I can't get the dash-which-button.py example to run locally. I get prev_n_clicks = n_clicks for both buttons, therefore it is impossible to know which button was clicked (I always get button 2).

screen shot 2018-07-03 at 10 49 24

I installed dash using conda:

dash                      0.21.1                     py_1    conda-forge
dash-core-components      0.23.0                     py_1    conda-forge
dash-html-components      0.11.0                     py_0    conda-forge
dash-renderer             0.13.0                     py_0    conda-forge
dash-table-experiments    0.6.0                     <pip>

BUG: dash-error-message-display

First of all, thank you for this great collection. It really helped me alot.

I was just trying to get some pop-up messages to work with dash. I tried the dash-display-error-message.py script, however couldn't get it to work.
In the Browser window I see the notice adding window.onerror, however the function doesn't get triggered on error. Status 500 is triggered by entering error in the input field "POST /_dash-update-component HTTP/1.1" 500 .

As I am no HTML-expert, any help would be appreciated.

Thanks!

Exception: Unexpected keyword argument `disabled`

Traceback (most recent call last):
File "/GIT/testProj_1/dash/test_1.py", line 11, in
value='test me'
File "", line 58, in init
File "\Python\Python27\site-packages\dash\development\base_component.py", line 31, in init
', '.join(sorted(self._prop_names))
Exception: Unexpected keyword argument disabled

Dash & XLwings. Attempting to pre-load Excel before Dash callback to save load time.

Windows 10 Enterprise for local. Windows Server 2022 Standard for the server

3.10 Python, Microsoft 365 Apps for enterprise, 0.28.7 xlwings

I have a web interface project that is using a connection between XLwings and Dash. The Excel file is large and takes about 15 seconds to load, while the calc only takes 5 seconds. Since it is setup to run over the web, each client will have their own instance of Excel. XLwings has a way to handle this.
Currently the setup is that once the user enters their setup and clicks submit, only then does the connection start.
If this was normal python, I could just start the connection earlier. However, with Dash the only connection between the layout, and the function definition is the Dash callback.
The goal is to load the Excel file as soon as the page is loaded, while that is happening the user would enter their parameters, the time that takes to load would be saved and the result return time would be shortened by that time.
*
I would like to use a chained callback. The first callback would load on page load with the xlWings connection. 'prevent_initial_call' would be false.
The final callback I have setup the 'prevent_initial_call' to True because I don't want this to run until they hit submit.
*
If I setup the connection as a variable or function, it doesn't look like you can pass these through the callback in anyway.
Project requirements are that the Excel and its VBA not be converted to Python/Dash.
Possible to launch one, or a few, Excels' on launch, and have XLwings grab the PID somehow? Would another Excel extension handle this? I know we're not supposed to use 'Global' variables, but that might fit this particular need.

Above this code part is the layout setup for Dash

@callback(
     #many Output and Inputs. Removed most for clarity.
     Output(component_id='table', component_property='data'),
     Input(component_id='yearSlider', component_property='value'),
)
def finalFxn(
#many parameters. Removed most for clarity.
parameter1,
parameter2
):
   with xw.App(visible=True) as app:
        wb = app.books.open(r"C:\Users\mike\Downloads\modified3-31.xlsm")
#logic
# excel cells = parameters from web
#logic
# parameters to web = excel 
return results, graph, etc.

LEGACY: dash-recipes/dash-dynamic-tabs.py seems outdated.

dash-recipes/dash-dynamic-tabs.py is an example that is meant to show that one can chose to display tabs based on a condition (in the example, a button click).
I would find this behaviour useful because you could potentailly differentiate tabs depending on user privilege. So the difficulty is that the tabs are only known at runtime.

The example in dash-dynamic-tabs seems to be outdated. It uses a construct like so:

dcc.Tabs(
    tabs=[ ...

while the current dash examples use:

dcc.Tabs(children=[
    dcc.Tab(),
    dcc.Tab() ...

My current solution is to add css styling to the tabs: {'display': 'none'} or {'display':'block'} depending on the condition, and to add app.config['suppress_callback_exceptions']=True after initializing the app.

If I find a better solution and manage to make it run, I will try to pull-request it. I am completely new to Dash, so I am not sure that I will achieve something.

Fix dash-asynchronous.py for dash 0.39.0

Hi

I have made asynchronous events work with dash 0.39.0 (where Event has been removed)
Here is the new code for dash-asynchronous.py
Note that this is tested under Winow10 thus I have used multithreaded setup (and single process)

[changes marked with trailing ###]

#################################################
import dash
from dash.dependencies import Input, Output ### removed Event from imports
import dash_core_components as dcc
import dash_html_components as html

import datetime
import time

class Semaphore:
def init(self, filename='semaphore.txt'):
self.filename = filename
with open(self.filename, 'w') as f:
f.write('done')

def lock(self):
    with open(self.filename, 'w') as f:
        f.write('working')

def unlock(self):
    with open(self.filename, 'w') as f:
        f.write('done')

def is_locked(self):
    return open(self.filename, 'r').read() == 'working'

semaphore = Semaphore()

def long_process():
if semaphore.is_locked():
raise Exception('Resource is locked')
semaphore.lock()
time.sleep(7)
semaphore.unlock()
return datetime.datetime.now()

app = dash.Dash()
server = app.server

def layout():
return html.Div([
html.Button('Run Process', id='button'),
dcc.Interval(id='interval', interval=500),
html.Div(id='lock'),
html.Div(id='output'),
])

app.layout = layout

@app.callback(
Output('lock', 'children'),
[Input('interval', 'n_intervals')]) ### New way to handle events for timers
def display_status(intervals):
return 'Running...' if semaphore.is_locked() else 'Free'

@app.callback(
Output('output', 'children'),
[Input('button', 'n_clicks')]) ### new way to handle events for buttons
def run_process(clicks):
return 'Finished at {}'.format(long_process()) if not clicks is None else '' ### no click at start

if name == 'main':
# app.run_server(debug=True, processes=5, threaded=False)
app.run_server(debug=True, processes=1, threaded=True) ### threaded mode (Windows10)

#################################################

here is my requirements.txt

#################################################
dash==0.39.0
dash-core-components==0.44.0
dash-html-components==0.14.0
dash-renderer==0.15.0
#################################################

Chris Arnault

multi-page-app not responding

The app contained within multi-page-app is not producing anything when run through a terminal in JupyterLab.

I have the same file structure:

  • app.py
  • index.py
  • apps
    • __init__.py
    • app1.py
    • app2.py

And run the command:

python app.py

And nothing is produced. Is there something being used in this code that has since been deprecated?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.