shinyproxy icon indicating copy to clipboard operation
shinyproxy copied to clipboard

ShinyProxy and Dash pages_plugin not redirecting as expected

Open uns1 opened this issue 3 years ago • 2 comments

I am trying to create a multi-page app using a new feature introduced in Dash 2 called "Pages" and host it through ShinyProxy More info here on Dash's new Pages functionality

While most of it works as expected using the demo dash application on ShinyProxy plus the minimal examples provided by Dash, the only issue I'm having is when it comes to first page you see once the container is loaded (i.e. path '/' for the dash app or home.py below)

app.py

import dash
import dash_bootstrap_components as dbc
import dash_labs as dl
import flask
import os

server = flask.Flask(__name__)

app = dash.Dash(__name__,
                plugins=[dl.plugins.pages],
                server=server,
                suppress_callback_exceptions=True,
                routes_pathname_prefix= os.environ['SHINYPROXY_PUBLIC_PATH'],
                requests_pathname_prefix= os.environ['SHINYPROXY_PUBLIC_PATH'],
                external_stylesheets=[dbc.themes.FLATLY, dbc.icons.FONT_AWESOME],
                )

navbar = dbc.NavbarSimple(
    dbc.DropdownMenu(
        [
            dbc.DropdownMenuItem(page["name"], href=page["path"])
            for page in dash.page_registry.values()
            if page["module"] != "pages.not_found_404"
        ],
        nav=True,
        label="More Pages",
    ),
    brand="Multi Page App Plugin Demo",
    color="light",
    dark=False,
)

app.layout = dbc.Container(
    [navbar, dl.plugins.page_container],
    className="dbc",
    fluid=True,
)

if __name__ == '__main__':


    app.run_server(debug=True,
                   use_reloader=True,
                   host='0.0.0.0',
                   port=8050
    )

Meanwhile, the pages directory contains two pages:

home.py

import dash
from dash import html
import os

dash.register_page(__name__, path=os.environ['SHINYPROXY_PUBLIC_PATH'])

def layout():
    # ...
    return html.Div(html.H1(['Home Baby Home']))

vendor.py

import dash
from dash import html, dcc
import os
import pandas as pd
import plotly.graph_objects as go

dash.register_page(__name__, path='vendor')


df = pd.read_csv(
    'https://gist.githubusercontent.com/chriddyp/' +
    '5d1ea79569ed194d432e56108a04d188/raw/' +
    'a9f9e8076b837d541398e999dcbac2b2826a81f8/'+
    'gdp-life-exp-2007.csv')


layout = html.Div([
    dcc.Graph(
        id='life-exp-vs-gdp',
        figure={
            'data': [
                go.Scatter(
                    x=df[df['continent'] == i]['gdp per capita'],
                    y=df[df['continent'] == i]['life expectancy'],
                    text=df[df['continent'] == i]['country'],
                    mode='markers',
                    opacity=0.7,
                    marker={
                        'size': 15,
                        'line': {'width': 0.5, 'color': 'white'}
                    },
                    name=i
                ) for i in df.continent.unique()
            ],
            'layout': go.Layout(
                xaxis={'type': 'log', 'title': 'GDP Per Capita'},
                yaxis={'title': 'Life Expectancy'},
                margin={'l': 40, 'b': 40, 't': 10, 'r': 10},
                legend={'x': 0, 'y': 1},
                hovermode='closest'
            )
        }
    )
])

The expectation above would be that when I open the app, the first thing I see would be in home.py as its path is positioned at "/ (or shiny proxy's public path)". However this is not the case, and instead I get a 404. However the 'vendor' path defined in vendor.py works as expected.

Screenshot of Home (problematic) image

Screenshot of Vendor (works as expected) image

Any ideas on why the opening page is not pointing towards home.py?

uns1 avatar May 06 '22 15:05 uns1

x-post on the Plotly forum

https://community.plotly.com/t/shinyproxy-dash-pages-plugin-not-redirecting-as-expected/64204

uns1 avatar Jun 03 '22 20:06 uns1

Hi

Thanks for opening this issue. I saw that you got some responses on the topic at the Plotly forum. Is this now working for you? If so, I'll try to update our example.

LEDfan avatar Aug 08 '22 14:08 LEDfan