-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shinylive Python Question: Importing from subfolders #162
Comments
Hi, can you provide a simple example app? |
Sure thing. I will try to get something to you tomorrow. |
My apologies for not providing an example app yet. I did discover the issue, and figured out why I felt like I "remembered" that it used to work. On personal projects I use a MacBook, and importing from modules organized into folders works fine in Shinylive. At work I use a Windows laptop, and that is where importing from folders runs into issues. The crux of it is this:
When I change the "\\" to a "/" in I didn't dig into your repo to see if the path is being generated in Python or something else like Javascript, but it seems like it's the kind of behavior created by The crude tool I hurriedly threw together today as a temporary workaround is just a script that finds those locations in import re
from pathlib import Path
filepath = Path(__file__).resolve().parent / "staging" / "app-name" / "app.json"
with open(filepath) as f:
text = f.read()
def fix_path_slashes(match_obj):
return re.sub(r"\\\\", "/", match_obj.group(1))
matches = re.findall(r'("name": "\S*.py", "content":)', text)
matches = [x for x in matches if "\\" in x]
if matches:
print("FIXING:")
for m in matches:
print(">", m.replace('"name": "', "").replace('", "content":', ""))
text = re.sub(r'("name": "\S*.py", "content":)', fix_path_slashes, text)
with open(filepath, "w") as f:
f.write(text) |
Curious if it's possible to import modules from local directory-based packages or folders. I feel like I was able to do this a couple of versions back, but I'm unable to now (it's also possible I'm just incorrectly remembering using regular py-shiny as well.
With larger apps/utilities, folders really help for organizing code (i.e., right now I have a utility that contains 28 other module files in the same directory as
app.py
), but I'm unable to figure out how to successfully import them (I've tried absolute imports, relative imports, regular folders, package folders, etc).Any direction is helpful. Thanks!
(btw - really enjoying Shinylive)
The text was updated successfully, but these errors were encountered: