Skip to content

Commit 5aaa249

Browse files
committed
including notes
1 parent 2ceaa36 commit 5aaa249

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

shiny/ui/_include_helpers.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def include_js(
8989
if method == "inline":
9090
return tags.script(read_utf8(file_path), **kwargs)
9191

92+
# QUESTION: Do we have access to the session or user at this point? Can write based on that and then give them full perms?
93+
# Where does cleanup happen?! Seems like maybe that needs to be included before we make new folders? Check the date? Tell if active
94+
# session using them?!
95+
9296
include_files = method == "link_files"
9397
path_dest, hash = maybe_copy_files(file_path, include_files)
9498

@@ -217,21 +221,35 @@ def maybe_copy_files(path: Path | str, include_files: bool) -> tuple[str, str]:
217221

218222
# To avoid unnecessary work when the same file is included multiple times,
219223
# use a directory scoped by a hash of the file.
224+
# We need to make tempdir deterministic if we use the pythong TemporaryDirectory class so we can still tell if the hash has changed
225+
# We want the temp dir unique to the process, hash should be the only thing that is dynamic based on the file contents.
226+
# Cleanup done using __del__?
227+
# Also make perms so that others can read it
228+
# Double check clean-up based on process ending
220229
tmpdir = os.path.join(tempfile.gettempdir(), "shiny_include_files", hash)
221230
path_dest = os.path.join(tmpdir, os.path.basename(path))
231+
print("tmpdir, path_dest: ", tmpdir, path_dest)
222232

223233
# Since the hash/tmpdir should represent all the files in the path's directory,
224234
# we can simply return here
225235
if os.path.exists(path_dest):
236+
print("path exists: ", path_dest, hash)
226237
return path_dest, hash
227238

228239
# Otherwise, make sure we have a clean slate
240+
# We only hit this if tempdir/ exists but not the file (i.e. style.css)
229241
if os.path.exists(tmpdir):
242+
print("clean the slate, tmpdir", tmpdir)
230243
shutil.rmtree(tmpdir)
231244

232245
if include_files:
246+
print("include files true")
247+
# TODO: Switch this to tempfile.mkdtmp? This will scope perms to the userID
248+
# QUESTION what is the user id? The system user? How does that work in Connect?
233249
shutil.copytree(os.path.dirname(path), tmpdir)
234250
else:
251+
print("include files false")
252+
# This should probably use the temp file syntax
235253
os.makedirs(tmpdir, exist_ok=True)
236254
shutil.copy(path, path_dest)
237255

@@ -240,11 +258,14 @@ def maybe_copy_files(path: Path | str, include_files: bool) -> tuple[str, str]:
240258

241259
def get_hash(path: Path | str, include_files: bool) -> str:
242260
if include_files:
243-
key = get_file_key(path)
244-
else:
245261
dir = os.path.dirname(path)
262+
# This is recursively listing everything in the dir and making that part of the hash even though we're not pulling it over
263+
# Ex. we make a hash, we copy over one file, then we jsut don't keep going
246264
files = glob.iglob(os.path.join(dir, "**"), recursive=True)
247265
key = "\n".join([get_file_key(x) for x in files])
266+
else:
267+
key = get_file_key(path)
268+
248269
return hash_deterministic(key)
249270

250271

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from shiny import App, ui
2+
3+
# Define the UI
4+
app_ui = ui.page_fluid(
5+
ui.include_css("./www/style.css"), # Reference the external CSS file
6+
ui.include_js("./www/customjs.js"),
7+
ui.h1("Simple Shiny App with External CSS"),
8+
ui.div(
9+
ui.p("This is a simple Shiny app that demonstrates ui.include_css()"),
10+
ui.p("The styling comes from an external CSS file!"),
11+
class_="content",
12+
),
13+
)
14+
15+
16+
# Define the server
17+
def server(input, output, session):
18+
pass
19+
20+
21+
# Create and run the app
22+
app = App(app_ui, server)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("heyo")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
body {
3+
background-color: #f0f8ff;
4+
font-family: Arial, sans-serif;
5+
}
6+
7+
h1 {
8+
color: #4682b4;
9+
border-bottom: 2px solid #4682b4;
10+
padding-bottom: 10px;
11+
}
12+
13+
.content {
14+
margin: 20px;
15+
padding: 15px;
16+
background-color: white;
17+
border-radius: 5px;
18+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
19+
}

0 commit comments

Comments
 (0)