Multiple Dashboards?


#21

A post was split to a new topic: URLs with a url_base_pathname


#22

Thanks Chris. Your post for setting up the multipage app using separate files was very useful to me. However, I am having problems getting dash_auth.BasicAuth working with this project structure. Using a similar project tree as you have listed above, I have the following:

app.py

import dash
import dash_auth

VALID_USERNAME_PASSWORD_PAIRS = [
    ['bob', 'loblaw']
]

app = dash.Dash('auth')
auth = dash_auth.BasicAuth(
    app,
    VALID_USERNAME_PASSWORD_PAIRS
]
server = app.server
app.config.suppress_callback_exceptions = True

Upon trying to run from index.py, I get the following error:

File ".../site-packages/dash_auth/auth.py", in line 16, in _overwrite_index
   original_index = self.app.server.view_functions['index']
KeyError: 'index'

which happens regardless of the order of the app.server and BasicAuth lines. Any thoughts?


#23

A post was split to a new topic: Multiple Page App - Google App Engine


#24

@chriddyp i was wondering if you or anyone else on this message board could assist me. I tried going the way of the tutorial you posted but to no avail {on how to create a multi-page Dash App} so I’m currently trying the other way {the method Vlad posted higher on this board}

My structure looks like this:

dash-project/
app1/
dash_1.py

app2/
dash_2.py

 ...

server.py
run.py

My run.py code is

from app import server as application
from app import app

import app_1.dash_1
import app_2.dash_2

My app.py code is:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from flask_mail import Mail
from flask_moment import Moment
from flask_login import LoginManager
from flask_pagedown import PageDown
from flask_migrate import Migrate, MigrateCommand
from flask_sslify import SSLify
from werkzeug.wsgi import DispatcherMiddleware
import os
import pandas as pd
import dash
import flask

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
from analysis import *

server=flask.Flask(name)
app = dash.Dash(name)
app.config.suppress_callback_exceptions = True

app.css.append_css({
‘external_url’: ‘https://codepen.io/chriddyp/pen/bWLwgP.css
})

My dash_1.py code is

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.graph_objs as go
from analysis import *

from app import app, server

app = dash.Dash(name=‘dash_1’, sharing=True, url_base_pathname=’/dash_1’, csrf_protect=False)

app.config[‘suppress_callback_exceptions’]=True

df = pd.read_csv(’/Users/WilliamStevens/Documents/deplorable_snowflake/ds/app_1/main.csv’)

layout = html.Div([
dcc.Graph(
id='Senators ',
figure={
‘data’: [
go.Scatter(
x=df[df[‘candidate_name’] == i][‘contributor_individual’],
y=df[df[‘candidate_name’] == i][‘contributor_pac’],
#z=df[df[‘candidate_name’] == i][‘contributor_total’],
text=df[df[‘candidate_name’] == i][‘contributor_total’],
mode=‘markers’,
opacity=0.7,
marker={
‘size’: 15,
‘line’: {‘width’: 0.5, ‘color’: ‘white’}
},
name=i
) for i in df.candidate_name.unique()
],
‘layout’: go.Layout(
xaxis={‘title’: ‘Contributor’},
yaxis={‘title’: ‘Contributor’},
#margin={‘l’: 40, ‘b’: 40, ‘t’: 10, ‘r’: 10},
#legend={‘x’: 0, ‘y’: 1},
hovermode=‘closest’
)
}
)
])

layout = html.Div(children=[
html.H1(children='Senators '),

html.Div(children='''
    God Bless .
'''),

dcc.Graph(
    id='main.csv',
    figure={
        'data': [
        {'x':df['x'], 'y': df['sector'], 'type': 'bar'},
        {'x':df['y'], 'y': df['industr'], 'type': 'bar'},
        {'x':df['z'], 'y': df['contributor'], 'type': 'bar'},
        ],
        'layout': {
            'title': 'Let Them Eat Cake ...'
        }
    }
)

])

My dash_2.py code is

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

from app import app, server

app = dash.Dash(name=‘dash_2’, sharing=True, url_base_pathname=’/dash_2’, csrf_protect=False)

app.config[‘suppress_callback_exceptions’]=True

df = pd.read_csv(’/Users/WilliamStevens/Documents/deplorable_snowflake/ds/app_2/slice.csv’)

layout = html.Div(children=[
html.H1(children=‘Barstool’),

html.Div(children='''
    One .
'''),

dcc.Graph(
    id='slice.csv',
    figure={
        'data': [
        {'x':df['Slice'], 'y': df['Score'], 'type': 'bar'},
        ],
        'layout': {
            'title': 'Bar'
        }
    }
)

])

When I run the app, all my other pages work except the /dash_1 & /dash_2 pages. Was wondering if you or anyone else could help out


#25

Hi
I have the same problem i don’t know where i have to write this uwsgi --http 0.0.0.0:5000 --processes 4 --wsgi-file run.py


#26

hi
where should i write this :uwsgi --http 0.0.0.0:5000 --processes 4 --wsgi-file run.py


#27

@chriddyp, this is awesome. Thanks!
One question, how could I also render an html template if the pathname == ‘/about’

I’ve tried to add this to the index.py file:

elif pathname == ‘/about’:
@server.route(’/about’)
def about():
return render_template(“about.html”)
else:
return ‘404’

It doesn’t return me an error, but simply the blank page.
Is there any solution by chance?