-
Notifications
You must be signed in to change notification settings - Fork 6
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
Refactor: Shinylive URL encode/decode #23
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Implement `__add__` and `__sub__` for all ShinyliveIoApp objects * +/- now return copies * `root_dir` can be None, new files are added "flattened" * More documentation
also for json, chunk, chunk_contents
This seems to be the preferred capitalization from other docs
@wch this is ready for final review. I updated the main PR post to reflect the changed behavior after your review yesterday. Some quick callouts:
|
wch
approved these changes
Jan 24, 2024
Co-authored-by: Winston Chang <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#20 introduced
shinylive url
commands and a set of functions to create and decode shinylive.io URLs. In practice, I've found the functions to be very helpful. But the functional design I used in #20 introduces some friction when I need to work with an app bundle and format it or manipulate it.This PR refactors the shinylive.io url encoding and decoding to use a central
ShinyliveApp
class that implements a number of useful methods. This makes it much easier to use the app bundle built withurl_encode()
orurl_decode()
in a variety of settings and to produce several outputs from the same set of app files, without having to reach into theshinylive._url
module.As part of this, I renamed
encode_shinylive_url()
anddecode_shinylive_url()
tourl_encode()
andurl_decode()
, since they'll most often be called asshinylive.url_encode()
.url_decode()
will now return aShinyliveApp
, whileurl_encode()
still returns the Shinylive URL as a string.The
ShinyliveApp
class implements:.to_url()
to return the shinylive.io URL.to_chunk_contents()
to create the shinylive chunk contents for a quarto shinylive chunk.to_chunk()
to create a complete shinylive chunk, including the header and options, from the app.to_json()
to return the JSON representation of the app bundle.write_files()
to write the app bundle to a directory.view()
to open the shinylive.io URL in a web browserThe
ShinyliveApp
constructor takes a ready-to-go app bundle oflist[FileContentJson]
, but most users will instead use class methods to construct theShinyliveApp
from various sources:.from_url()
decodes a URL into aShinyliveApp
.from_local()
creates aShinyliveApp
from a set of local files.from_text()
creates aShinyliveApp
from a string with the contents ofapp.py
orapp.R
(optionally with support of localfiles
).Once created, there are additional methods to help add to or remove from the app bundle. These methods all allow for method chaining.
.add_file()
,add_files()
or.add_file_contents()
(i.e. text files with a given name),.remove_file()
to take a file, by name, out of the bundle.Additionally, I implemented
+
and-
operators for the local app class to add and remove files from the bundle.