Skip to content
Commits on Source (5)
env
\ No newline at end of file
FROM renku/renkulab-py:python-3.8.8-15f091e
FROM renku/renkulab-py:3.9-0.11.1
COPY . /work
COPY jupyter_notebook_config.py ~/.jupyter/
COPY requirements.txt /work/requirements.txt
RUN pip install -r /work/requirements.txt
RUN jupyter lab build
COPY jupyter_notebook_config.py ~/.jupyter/
COPY . /work
WORKDIR /work
......@@ -4,26 +4,32 @@ Source: https://towardsdatascience.com/dash-for-beginners-create-interactive-pyt
"""
import flask
import dash
from dash import html
from dash import dcc
import plotly.graph_objects as go
import plotly.express as px
import argparse
import os
from urllib.parse import urlparse, urljoin
from jupyter_dash import JupyterDash
# JupyterDash.infer_jupyter_proxy_config() # TODO not sure if this does anything useful in our setting
from utils import get_session_path
app = JupyterDash(__name__) # initialising dash app
server = app.server
parser = argparse.ArgumentParser()
parser.add_argument("--port", type=int)
args = parser.parse_args()
JupyterDash.infer_jupyter_proxy_config()
session_path = get_session_path()
proxy_base_path = f"{session_path}/proxy/{args.port}/"
app = JupyterDash(requests_pathname_prefix=proxy_base_path) # initialising dash app
df = px.data.stocks() # reading stock price dataset
def stock_prices():
# Function for creating line chart showing Google stock prices over time
fig = go.Figure([go.Scatter(x=df['date'], y=df['GOOG'],
fig = go.Figure([go.Scatter(x=df['date'], y=df['GOOG'], \
line=dict(color='firebrick', width=4), name='Google')
])
fig.update_layout(title='Prices over time',
......@@ -43,4 +49,6 @@ app.layout = html.Div(id='parent', children=[
if __name__ == '__main__':
app.run_server(mode="external", port=8050, host="0.0.0.0")
app.run_server(
mode="jupyterlab", port=args.port, host="localhost"
)
# Configuration file for jupyter-notebook.
c.ServerProxy.servers = {
'dash': { # the name of the environment
'command': ['gunicorn', 'app:server', "-b", ":8050"],
'port': 8050
'dash': {
'command': [
'python',
'app.py',
'--port',
'{port}',
],
'absolute_url': False,
}
}
\ No newline at end of file
}
......@@ -5,4 +5,4 @@ plotly
pandas
jupyter-server-proxy
jupyter-dash
gunicorn
\ No newline at end of file
escapism
\ No newline at end of file
from hashlib import md5
import os
import escapism
from subprocess import check_output
# Update the namespace below to match the namespace of the project
# This can be derived from the URL to your project
# I.e. for a renku project like
# https://renkulab.io/projects/group1/group2/tasko.olevski/dash-jupyter-server-proxy-example
# the namespace will be group1/group2/tasko.olevski
# This is needed because I cannot determine this from within a session
namespace = "tasko.olevski" # The gitlab project namespace
def get_safe_username():
username = os.getenv("RENKU_USERNAME")
if not username:
raise ValueError("Cannot determine username for creating session path.")
return escapism.escape(username, escape_char="-").lower()
def get_current_branch():
return check_output(["git", "branch", "--show-current"]).decode().strip("\n\r\t'")
def get_server_name():
"""Form a 16-digit hash server ID."""
safe_username = get_safe_username()
project = os.getenv("PROJECT_NAME")
if not project:
raise ValueError("Cannot determine project name for creating session path")
branch = get_current_branch()
commit_sha = os.getenv("CI_COMMIT_SHA")
if not commit_sha:
raise ValueError("Cannot determine commit sha for creating session path")
server_string = f"{safe_username}-{namespace}-{project}-{branch}-{commit_sha}"
return "{username}-{project}-{hash}".format(
username=safe_username[:10].lower(),
project=escapism.escape(project, escape_char="-")[:24].lower(),
hash=md5(server_string.encode()).hexdigest()[:8].lower(),
)
def get_session_path():
server_name = get_server_name()
return f"/sessions/{server_name}"
\ No newline at end of file