Skip to content

Commit

Permalink
add scripts from cli (#680)
Browse files Browse the repository at this point in the history
* add scripts from cli

* add warning when including scripts

* flake8 fixes

* confirm scripts injection
  • Loading branch information
csweaver authored Apr 22, 2019
1 parent 9c6273e commit ea187f4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 36 deletions.
51 changes: 29 additions & 22 deletions client/index_template.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>cellxgene</title>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed:400,400i,700" rel="stylesheet">
<style>
html, body, p, h1, h2, h3, h4, h5, h6, span, button, input, label, text, div {
font-family: 'Roboto Condensed','Helvetica Neue','Helvetica','Arial',sans-serif;
font-size: 14px;
}
body {
margin: 0;
padding: 0;
}
html, body, p, h1, h2, h3, h4, h5, h6, span, button, input, label, text, div {
font-family: 'Roboto Condensed', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
font-size: 14px;
}

* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}

* {
box-sizing: border-box;
}
</style>
</head>
<body>

</head>
<body>
<script type="text/javascript">
window.CELLXGENE = {};
window.CELLXGENE.API = {
prefix: window.location.href + "api/",
version: "v0.2/"
};
window.CELLXGENE = {};
window.CELLXGENE.API = {
prefix: window.location.href + "api/",
version: "v0.2/"
};
</script>
<noscript>If you're seeing this message, that means <strong>JavaScript has been disabled on your browser</strong>, please <strong>enable JS</strong> to make this app work.</noscript>
<noscript>If you're seeing this message, that means <strong>JavaScript has been disabled on your browser</strong>,
please <strong>enable JS</strong> to make this app work.
</noscript>

<div id="root"></div>
</body>
<div id="root"></div>
{% for script in SCRIPTS %}
<script type="text/javascript" src="{{script | safe}}"></script>
{% endfor %}
</body>
</html>
3 changes: 2 additions & 1 deletion server/app/web/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@bp.route("/")
def index():
dataset_title = current_app.config["DATASET_TITLE"]
return render_template("index.html", datasetTitle=dataset_title)
scripts = current_app.config["SCRIPTS"]
return render_template("index.html", datasetTitle=dataset_title, SCRIPTS=scripts)


@bp.route("/favicon.png")
Expand Down
48 changes: 35 additions & 13 deletions server/cli/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,28 @@
show_default=True,
help="Relative expression cutoff used when selecting top N differentially expressed genes",
)
@click.option(
"--scripts",
default=[],
multiple=True,
help="Additional script files to include in html page",
show_default=True,
)
def launch(
data,
layout,
diffexp,
title,
verbose,
debug,
obs_names,
var_names,
open_browser,
port,
host,
max_category_items,
diffexp_lfc_cutoff,
data,
layout,
diffexp,
title,
verbose,
debug,
obs_names,
var_names,
open_browser,
port,
host,
max_category_items,
diffexp_lfc_cutoff,
scripts,
):
"""Launch the cellxgene data viewer.
This web app lets you explore single-cell expression data.
Expand All @@ -106,6 +114,19 @@ def launch(
else:
warnings.formatwarning = custom_format_warning

if scripts:
click.echo(r"""
/ / /\ \ \__ _ _ __ _ __ (_)_ __ __ _
\ \/ \/ / _` | '__| '_ \| | '_ \ / _` |
\ /\ / (_| | | | | | | | | | | (_| |
\/ \/ \__,_|_| |_| |_|_|_| |_|\__, |
|___/
The --scripts flag is intended for developers to include google analytics etc. You could be opening yourself to a
security risk by including the --scripts flag. Make sure you trust the scripts that you are including.
""")
scripts_pretty = ", ".join(scripts)
click.confirm(f"Are you sure you want to inject these scripts: {scripts_pretty}?", abort=True)

if not verbose:
sys.tracebacklimit = 0

Expand All @@ -121,6 +142,7 @@ def launch(

app = server.create_app()
app.config.update(DATASET_TITLE=title)
app.config.update(SCRIPTS=scripts)

if not verbose:
log = logging.getLogger("werkzeug")
Expand Down

0 comments on commit ea187f4

Please sign in to comment.