posit-dev / py-shinylive

Python package for deploying Shinylive applications
https://shiny.posit.co/py/docs/shinylive.html
MIT License
42 stars 4 forks source link

Refactor: Shinylive URL encode/decode #23

Closed gadenbuie closed 6 months ago

gadenbuie commented 6 months ago

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 with url_encode() or url_decode() in a variety of settings and to produce several outputs from the same set of app files, without having to reach into the shinylive._url module.

As part of this, I renamed encode_shinylive_url() and decode_shinylive_url() to url_encode() and url_decode(), since they'll most often be called as shinylive.url_encode().

url_decode() will now return a ShinyliveApp, while url_encode() still returns the Shinylive URL as a string.

The ShinyliveApp class implements:

The ShinyliveApp constructor takes a ready-to-go app bundle of list[FileContentJson], but most users will instead use class methods to construct the ShinyliveApp from various sources:

Once created, there are additional methods to help add to or remove from the app bundle. These methods all allow for method chaining.

Additionally, I implemented + and - operators for the local app class to add and remove files from the bundle.

gadenbuie commented 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: