Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion .github/scripts/plotly_cloud_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import json
import os
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -73,7 +74,8 @@ def team_id(c) -> str:
sys.exit("PLOTLY_TEAM is not set")
r = c.get("/teams")
r.raise_for_status()
teams = r.json()
# Shape: {"teams": [{"team": {"id", "name", ...}, "role": ...}, ...]}
teams = [m["team"] for m in r.json()["teams"]]
for t in teams:
if wanted.lower() in (t.get("name", "").lower(), t.get("id", "").lower()):
return t["id"]
Expand Down Expand Up @@ -101,6 +103,40 @@ def app_link(app: dict | None) -> str:
return "(url unavailable)"


def url_slug(name: str) -> str:
"""App name -> subdomain: lowercase, anything not [a-z0-9] becomes '-'."""
return re.sub(r"[^a-z0-9]+", "-", name.lower()).strip("-")


def ensure_url(c, app: dict | None, name: str) -> dict | None:
"""Point the app at <slug-of-name>.plotly.app. Warns (doesn't fail) if the
URL is taken, since subdomains are unique across all of Plotly Cloud."""
if not app:
return app
slug = url_slug(name)
if app.get("app_url") == slug:
return app
r = c.put(f"/app/{app['id']}", json={"appUrl": slug})
if r.is_success:
log(f"Set URL of {name} to {slug}.plotly.app")
return {**app, "app_url": slug}
log(f"warning: could not set URL of {name} to '{slug}': {r.status_code} {r.text}")
return app


def ensure_visibility(c, app: dict | None, name: str, *, private: bool) -> dict | None:
"""Set "Anyone with the link" access: private = No access, public = Can view.
Team-member edit rights aren't exposed by the API; set those in the app's
Sharing settings."""
if not app or app.get("is_view_private") is private:
return app
r = c.put(f"/app/{app['id']}", json={"isViewPrivate": "private" if private else "public"})
if r.is_success:
log(f"Set {name} to {'private' if private else 'public'}")
return {**app, "is_view_private": private}
sys.exit(f"Setting visibility of {name} failed: {r.status_code} {r.text}")


def publish(project: Path, tid: str, *, app_id: str | None = None, name: str | None = None) -> None:
cmd = [
"plotly", "app", "publish",
Expand Down Expand Up @@ -150,6 +186,8 @@ def cmd_staging(apps: list[str]) -> None:
log(f"Creating {name}")
publish(project, tid, name=name)
deployed = find_by_name(team_apps(c, tid), name)
deployed = ensure_visibility(c, deployed, name, private=True)
deployed = ensure_url(c, deployed, name)
summary(f"- **{app}** → {app_link(deployed)}")


Expand Down Expand Up @@ -202,6 +240,8 @@ def cmd_production(apps: list[str]) -> None:
publish(project, tid, name=name)

deployed = find_by_name(team_apps(c, tid), name) or target
deployed = ensure_visibility(c, deployed, name, private=False)
deployed = ensure_url(c, deployed, name)
summary(f"- **{app}** → {app_link(deployed)}")


Expand Down
6 changes: 3 additions & 3 deletions dash-news/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def process_news_data(news_articles, current_page, articles_per_page=15):
),
html.Div(
[
html.Label("Select Category:", className="dropdown-label"),
html.Label("Choose a Category:", className="dropdown-label"),
dcc.Dropdown(
id="category-dropdown",
options=CATEGORIES,
Expand All @@ -169,11 +169,11 @@ def process_news_data(news_articles, current_page, articles_per_page=15):
html.Div(
[
html.Button(
"Previous", id="prev-button", className="pagination-btn"
"← Previous", id="prev-button", className="pagination-btn"
),
html.Span(id="page-info", className="page-info"),
html.Button(
"Next", id="next-button", className="pagination-btn"
"Next →", id="next-button", className="pagination-btn"
),
],
className="pagination-container",
Expand Down
Loading