Skip to content

Instantly share code, notes, and snippets.

@antoinerg
Last active July 20, 2020 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoinerg/be7f5123f4e893fcc37a1782dcbe1d4e to your computer and use it in GitHub Desktop.
Save antoinerg/be7f5123f4e893fcc37a1782dcbe1d4e to your computer and use it in GitHub Desktop.
serve Dash app as a subdirectory
# -*- coding: utf-8 -*-
# Run this app with `DASH_URL_BASE_PATHNAME=/MY_PREFIX/ python app.py` and
# visit http://127.0.0.1:8050/MY_PREFIX/ in your web browser.
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})
fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
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=fig
)
])
if __name__ == '__main__':
app.run_server(debug=True)
let
nixpkgs = builtins.fetchGit {
name = "nixos-20.03";
url = "https://github.com/nixos/nixpkgs-channels/";
# `git ls-remote https://github.com/nixos/nixpkgs-channels nixos-20.03`
ref = "refs/heads/nixos-20.03";
rev = "ab3adfe1c769c22b6629e59ea0ef88ec8ee4563f";
};
pkgs = import nixpkgs {};
python = pkgs.python37.withPackages(ps: with ps; [ pandas dash ]);
in
pkgs.stdenv.mkDerivation {
name = "dash-sub-folder";
src = ./.;
buildInputs = [python];
installPhase = ''
mkdir -p $out/bin
echo -e "#!/bin/sh\n\n${python.interpreter} $src/app.py" > $out/bin/server
chmod +x $out/bin/server
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment