Skip to content

Commit 6488c37

Browse files
committed
Updating the js scripts
1 parent f00c2b9 commit 6488c37

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

shiny/ui/_include_helpers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def include_js(
3636
method
3737
One of the following:
3838
39-
* ``"link"`` is the link to the CSS file via a :func:`~shiny.ui.tags.link` tag. This
39+
* ``"link"`` is the link to the JS file via a :func:`~shiny.ui.tags.link` tag. This
4040
method is generally preferable to ``"inline"`` since it allows the browser to
4141
cache the file.
42-
* ``"link_files"`` is the same as ``"link"``, but also allow for the CSS file to
42+
* ``"link_files"`` is the same as ``"link"``, but also allow for the JS file to
4343
request other files within ``path``'s immediate parent directory (e.g.,
4444
``@import()`` another file). Note that this isn't the default behavior because
4545
you should **be careful not to include files in the same directory as ``path``
@@ -48,7 +48,7 @@ def include_js(
4848
example, if the app's source is located at ``/app/app.py``, then ``path``
4949
should be somewhere like ``/app/css/custom.css`` (and all the other relevant
5050
accompanying 'safe' files should be located under ``/app/css/``).
51-
* ``"inline"`` is the inline the CSS file contents within a
51+
* ``"inline"`` is the inline the JS file contents within a
5252
:func:`~shiny.ui.tags.style` tag.
5353
**kwargs
5454
Attributes which are passed on to `~shiny.ui.tags.script`.
@@ -234,7 +234,6 @@ def maybe_copy_files(path: Path | str, include_files: bool) -> tuple[str, str]:
234234
else:
235235
os.makedirs(tmpdir, exist_ok=True)
236236
shutil.copy(path, path_dest)
237-
238237
return path_dest, hash
239238

240239

tests/playwright/shiny/bugs/2061-css-js-inclusion/app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
from shiny import App, Inputs, Outputs, Session, ui
44

55
js_file = Path(__file__).parent / "js" / "customjs.js"
6+
# We don't know what the temp dir will be called until we make it and that's what we need to reference
7+
# in the app (ex. we can't just reference where it is pre-copy)
8+
js2_file = (
9+
ui.include_js(js_file, method="link_files").attrs["src"][:-11] + "customjs2.js"
10+
)
611
css_file = Path(__file__).parent / "css" / "style.css"
712

813
# Define the UI
914
app_ui = ui.page_fluid(
1015
ui.include_css(css_file, method="link_files"),
1116
ui.include_js(js_file, method="link_files"),
17+
ui.tags.script(src=str(js2_file)),
1218
ui.h1("Simple Shiny App with External CSS"),
1319
ui.div(
1420
ui.p("This is a simple Shiny app that demonstrates ui.include_css()"),

tests/playwright/shiny/bugs/2061-css-js-inclusion/css/more.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/playwright/shiny/bugs/2061-css-js-inclusion/css/style.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import url("more.css");
2-
31
body {
42
font-family: Arial, sans-serif;
53
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const special = document.createElement('p');
2+
special.textContent = 'Also here!';
3+
document.body.appendChild(special);

tests/playwright/shiny/bugs/2061-css-js-inclusion/test_css-js-inclusion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
def test_inclusion(page: Page, local_app: ShinyAppProc) -> None:
77
page.goto(local_app.url)
88

9-
expect(page.locator("body > p")).to_have_text("Heyo!")
9+
expect(page.locator("body > p").first).to_have_text("Heyo!")
10+
expect(page.locator("body > p").last).to_have_text("Also here!")

0 commit comments

Comments
 (0)