Add include_javascript(), include_css(), and include_html()#127
Conversation
|
linked to posit-dev/py-htmltools#42 |
Co-authored-by: Winston Chang <winston@stdout.org>
Co-authored-by: Winston Chang <winston@stdout.org>
Co-authored-by: Winston Chang <winston@stdout.org>
Co-authored-by: Winston Chang <winston@stdout.org>
wch
left a comment
There was a problem hiding this comment.
I had some more thoughts about path handling and the user experience. What happens if someone writes this reasonable-looking code?
app_ui = ui.page_fluid(
ui.include_css("css/my_styles.css"),
...
)It's a relative path, but we can make any assumptions about which directory is the current working directory. This could result in a not-very-clear error that will leave the user scratching their head.
So we may want to test that the path is an absolute path at the top of include_js and include_css, with something roughly like:
path = Path(path)
if not path.is_absolute():
raise RuntimeError('include_js() requires an absolute path. Please use
include_js(Path(__file__)).parent / "myfile.css"') (But with a better error message)
The other comments I have about Path are related to this. When the PR was originally created, we mostly used os.path, but since then we generally switched to pathlib.Path.
|
@wch It seems like |
|
The issue is that if you start the app from a different directory, then the path will be relative to that directory. For example: We would want it the printed path to be As far as I know, the only reasonable way to do that is to have the user provide |
|
Oh I see, so we really want to be checking if the file exists? I'm not sure we want to enforce the What about this: |
Yes, that makes sense.
Good point. I think we should use the
That sounds good to me. |
Currently requires posit-dev/py-htmltools#32 (since, if we want to return a
Tag, we need to know the finalsrc/href).TODO:
include_markdown()that utilizesmarkdown()?include_html()intoinclude_html()andinclude_html_frame()?include_html()/include_html_frame()examples