Skip to content

Commit 3188b86

Browse files
authored
Enable error console when running locally. (#1060)
1 parent 5faf62b commit 3188b86

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
* `ui.value_box()`, `ui.layout_columns()` and `ui.layout_column_wrap()` now all have `min_height` and `max_height` arguments. These are useful in filling layouts, like `ui.page_fillable()`, `ui.page_sidebar(fillable=True)` or `ui.page_navbar(fillable=True)`. For example, you can use `ui.layout_columns(min_height=300, max_height=500)` to ensure that a set of items (likely arranged in a row of columns) are always between 300 and 500 pixels tall. (#1223)
2525

26+
* Added an error console which displays errors in the browser's UI. This is enabled by default when running applications locally, and can be disabled with `shiny run --no-dev-mode`. It is not enabled for applications that are deployed to a server. (#1060)
27+
2628
### Bug fixes
2729

2830
* On Windows, Shiny Express app files are now read in as UTF-8. (#1203)

shiny/_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def _render_page(self, ui: Tag | TagList, lib_prefix: str) -> RenderedHTML:
438438
ui_res = copy.copy(ui)
439439
# Make sure requirejs, jQuery, and Shiny come before any other dependencies.
440440
# (see require_deps() for a comment about why we even include it)
441-
ui_res.insert(0, [require_deps(), jquery_deps(), shiny_deps()])
441+
ui_res.insert(0, [require_deps(), jquery_deps(), *shiny_deps()])
442442
rendered = HTMLDocument(ui_res).render(lib_prefix=lib_prefix)
443443
self._ensure_web_dependencies(rendered["dependencies"])
444444
return rendered
@@ -449,7 +449,7 @@ def _render_page_from_file(self, file: Path, lib_prefix: str) -> RenderedHTML:
449449

450450
doc = HTMLTextDocument(
451451
page_html,
452-
deps=[require_deps(), jquery_deps(), shiny_deps()],
452+
deps=[require_deps(), jquery_deps(), *shiny_deps()],
453453
deps_replace_pattern='<meta name="shiny-dependency-placeholder" content="">',
454454
)
455455

shiny/_main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ def main() -> None:
143143
help="Launch app browser after app starts, using the Python webbrowser module.",
144144
show_default=True,
145145
)
146+
@click.option(
147+
"--dev-mode/--no-dev-mode",
148+
is_flag=True,
149+
default=True,
150+
help="Dev mode",
151+
show_default=True,
152+
)
146153
@no_example()
147154
def run(
148155
app: str | shiny.App,
@@ -159,6 +166,7 @@ def run(
159166
app_dir: str,
160167
factory: bool,
161168
launch_browser: bool,
169+
dev_mode: bool,
162170
**kwargs: object,
163171
) -> None:
164172
reload_includes_list = reload_includes.split(",")
@@ -177,6 +185,7 @@ def run(
177185
app_dir=app_dir,
178186
factory=factory,
179187
launch_browser=launch_browser,
188+
dev_mode=dev_mode,
180189
**kwargs,
181190
)
182191

@@ -196,6 +205,7 @@ def run_app(
196205
app_dir: Optional[str] = ".",
197206
factory: bool = False,
198207
launch_browser: bool = False,
208+
dev_mode: bool = True,
199209
**kwargs: object,
200210
) -> None:
201211
"""
@@ -276,6 +286,8 @@ def run_app(
276286

277287
os.environ["SHINY_HOST"] = host
278288
os.environ["SHINY_PORT"] = str(port)
289+
if dev_mode:
290+
os.environ["SHINY_DEV_MODE"] = "1"
279291

280292
if isinstance(app, str):
281293
# Remove ":app" suffix if present. Normally users would just pass in the

shiny/html_dependencies.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
from __future__ import annotations
2+
3+
import os
4+
15
from htmltools import HTMLDependency
26

37

4-
def shiny_deps() -> HTMLDependency:
5-
return HTMLDependency(
6-
name="shiny",
7-
version="0.0.1",
8-
source={"package": "shiny", "subdir": "www/shared/"},
9-
script={"src": "shiny.js"},
10-
stylesheet={"href": "shiny.min.css"},
11-
)
8+
def shiny_deps() -> list[HTMLDependency]:
9+
deps = [
10+
HTMLDependency(
11+
name="shiny",
12+
version="0.0.1",
13+
source={"package": "shiny", "subdir": "www/shared/"},
14+
script={"src": "shiny.js"},
15+
stylesheet={"href": "shiny.min.css"},
16+
)
17+
]
18+
if os.getenv("SHINY_DEV_MODE") == "1":
19+
deps.append(
20+
HTMLDependency(
21+
"shiny-devmode",
22+
version="0.0.1",
23+
head="<script>window.__SHINY_DEV_MODE__ = true;</script>",
24+
)
25+
)
26+
27+
return deps
1228

1329

1430
def jquery_deps() -> HTMLDependency:

0 commit comments

Comments
 (0)