Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5aaa249
including notes
elnelson575 Aug 25, 2025
cc15245
Removing notes to self
elnelson575 Aug 25, 2025
e6b8260
cleanup
elnelson575 Aug 25, 2025
0fb5ccf
Merge branch 'main' into fix/js_css_inclusion
elnelson575 Aug 25, 2025
f4c53fd
With prints
elnelson575 Aug 26, 2025
2764cbe
Add multifile example, notes
elnelson575 Aug 26, 2025
03839f0
Fixing types
elnelson575 Aug 26, 2025
649c856
Merge branch 'fix/js_css_inclusion' of github.com:posit-dev/py-shiny …
elnelson575 Aug 26, 2025
c1a11a1
Updating tests
elnelson575 Aug 27, 2025
ff8581e
Debugging
elnelson575 Aug 27, 2025
c888903
fixes
elnelson575 Aug 27, 2025
e99f795
Deleting old test
elnelson575 Aug 27, 2025
c1d7568
Merging in changes from other branch
elnelson575 Aug 27, 2025
14012c8
Added comments, minor changes
elnelson575 Aug 28, 2025
7ffeab5
Relinking vs inline
elnelson575 Aug 28, 2025
63a3c40
Update shiny/ui/_include_helpers.py
elnelson575 Aug 28, 2025
6609d20
Updating prints
elnelson575 Aug 28, 2025
b477812
Updating 'shiny_include_files to have 777 perms
elnelson575 Aug 29, 2025
30fc4f7
Testing only new dir change
elnelson575 Sep 2, 2025
87afb30
Updating to deal with 404
elnelson575 Sep 3, 2025
8ae6460
Updating one missing piece
elnelson575 Sep 3, 2025
74c931e
Removing prints
elnelson575 Sep 4, 2025
26fedcc
Updatign changelog
elnelson575 Sep 4, 2025
b48aea9
Minor edit
elnelson575 Sep 4, 2025
88a9fee
Merge branch 'main' into fix/js_css_include_perms
elnelson575 Sep 4, 2025
e4fea42
Updating tests
elnelson575 Sep 4, 2025
cee6f3e
Updated changelog and comment placement
elnelson575 Sep 4, 2025
9004f58
Updating test name
elnelson575 Sep 4, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

* Fixed several issues related to including custom js and css fil
* JS and CSS file loaded with `include_js()` or `include_css()` will be loaded into a new temporary directory. (#2061)
* JS and CSS files in the same directory will be loaded correctly. (#729)

* Fixed numerous issues related to programmatically updating selectize options. (#2053)
* `update_selectize(options=...)` no longer gets ignored when `server=False` (the default).
* `update_selectize(options=...)` now works as expected in a module.
Expand Down
8 changes: 4 additions & 4 deletions shiny/ui/_include_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ def create_include_dependency(
def maybe_copy_files(path: Path | str, include_files: bool) -> tuple[str, str]:
hash = get_hash(path, include_files)

# To avoid unnecessary work when the same file is included multiple times,
# use a directory scoped by a hash of the file.
tmpdir = os.path.join(tempfile.gettempdir(), "shiny_include_files", hash)
tmpdir = os.path.join(tempfile.gettempdir(), f"shiny_include_{hash}")
path_dest = os.path.join(tmpdir, os.path.basename(path))

# To avoid unnecessary work when the same file is included multiple times,
# use a directory scoped by a hash of the file.
# Since the hash/tmpdir should represent all the files in the path's directory,
# we can simply return here
# we can check if it exists to determine if we have a cache hit
if os.path.exists(path_dest):
return path_dest, hash

Expand Down
Copy link
Collaborator

@cpsievert cpsievert Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is for the other PR, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nvm, I think I see why we're adding the test -- it's not that we're directly testing this fix, it's more about adding coverage that should've already existed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because we're altering how we include files, I want to have a test for both "link_files" and "link" versions

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pathlib import Path

from shiny import App, Inputs, Outputs, Session, ui

js_file = Path(__file__).parent / "customjs.js"
css_file = Path(__file__).parent / "style.css"

# Define the UI
app_ui = ui.page_fluid(
ui.include_css(css_file, method="link"),
ui.include_js(js_file, method="link"),
ui.h1("Simple Shiny App with External CSS"),
ui.div(
ui.p("This is a simple Shiny app that demonstrates ui.include_css()"),
ui.p("The styling comes from an external CSS file!"),
class_="content",
),
)


# Define the server
def server(input: Inputs, output: Outputs, session: Session):
pass


# Create and run the app
app = App(app_ui, server)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const newParagraph = document.createElement('p');
newParagraph.textContent = 'Heyo!';
document.body.appendChild(newParagraph);

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
body {
background-color: #70bfef;
font-family: Arial, sans-serif;
}

h1 {
color: black;
border-bottom: 2px solid #4682b4;
padding-bottom: 10px;
}

.content {
margin: 20px;
padding: 15px;
background-color: white;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from playwright.sync_api import Page, expect

from shiny.run import ShinyAppProc


def test_inclusion(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

expect(page.locator("body > p")).to_have_text("Heyo!")
Loading