Closed gadenbuie closed 6 months ago
@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:
ShinyliveApp
class with alternate constructors .from_url()
, .from_local()
and .from_text()
.url_encode()
returns the URL string but the ShinyliveApp
is now exported..url()
, .json()
, etc. to .to_url()
, .to_json()
...__init__
.host
is now a class attribute that defaults to https://shinylive.io
but is parsed from the url
in .from_url()
.
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.