Skip to content
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 30 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f829802
Refactor `url_{encode,decode}` to return a ShinyliveIoApp object
gadenbuie Jan 22, 2024
babd4fe
Add +/- methods for ShinyliveIoAppLocal
gadenbuie Jan 22, 2024
88a086c
docs: document all the things
gadenbuie Jan 22, 2024
4ae8018
feat(url_decode): Track mode/header in object
gadenbuie Jan 22, 2024
279a934
tests: Add some very basic tests
gadenbuie Jan 22, 2024
d7d17fa
docs: update news
gadenbuie Jan 22, 2024
d992c1d
fix: Missed setting language
gadenbuie Jan 22, 2024
8481904
fix: chunk engine is `shinylive-python` not `shinylive-py`
gadenbuie Jan 22, 2024
789e395
fix: Use snakecase for `viewer_height`
gadenbuie Jan 22, 2024
4614ffb
several improvements
gadenbuie Jan 23, 2024
be82671
feat: Add `add_dir()` method
gadenbuie Jan 23, 2024
bf0c661
chore: ShinyLive -> shinylive
gadenbuie Jan 23, 2024
885f84e
remove some unnecessary pythonic fanciness
gadenbuie Jan 23, 2024
b299175
Make mode, header, host public and document
gadenbuie Jan 23, 2024
05d9bcc
Add alternate constructors
gadenbuie Jan 23, 2024
d7af495
Rename class ShinyliveApp
gadenbuie Jan 23, 2024
7aa7f94
update `url_encode()` to return a string
gadenbuie Jan 23, 2024
57614ca
flip order of logical section, to prioritize True
gadenbuie Jan 23, 2024
2392841
export ShinyliveApp
gadenbuie Jan 23, 2024
8762f7a
simplify setting language attribute
gadenbuie Jan 23, 2024
d323be6
update CLI to use new ShinyliveApp constructors
gadenbuie Jan 23, 2024
1420ac0
tests: fix tests
gadenbuie Jan 23, 2024
23d15f1
fix setting header in constructor
gadenbuie Jan 23, 2024
72e9596
Add `.remove_file()` method and call in `__sub__`
gadenbuie Jan 24, 2024
9305869
Allow method chaining in ShinyliveApp methods
gadenbuie Jan 24, 2024
87fc46e
rename methods `.url()` -> `.to_url()`
gadenbuie Jan 24, 2024
6907ec2
docs: update changelog
gadenbuie Jan 24, 2024
dbc60bc
docs: shinylive -> Shinylive
gadenbuie Jan 24, 2024
95ab265
remove trailing slashes from host
gadenbuie Jan 24, 2024
21a51fe
Update reference to ShinyliveIoApp
gadenbuie Jan 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED]

* Added `shinylive url encode` and `shinylive url decode` commands to encode local apps into a shinylive.io URL or decode a shinylive.io URL into local files. These commands are accompanied by `encode_shinylive_url()` and `decode_shinylive_url()` functions for programmatic use. (#20)
* Added `shinylive url encode` and `shinylive url decode` commands to encode local apps into a [shinylive.io](https://shinylive.io) URL or decode a [shinylive.io](https://shinylive.io) URL into local files. These commands are accompanied by `url_encode()` and `url_decode()` functions for programmatic use. They are supported by the new `ShinyliveIoApp` class which provides methods to get the app URL, save the app locally, or create a [Shinylive quarto chunk](https://quarto-ext.github.io/shinylive/) from the app's files. (#20, #23)

## [0.1.3] - 2024-12-19

Expand Down
4 changes: 2 additions & 2 deletions shinylive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""A package for packaging Shiny applications that run on Python in the browser."""

from ._url import decode_shinylive_url, encode_shinylive_url
from ._url import ShinyliveApp, url_decode, url_encode
from ._version import SHINYLIVE_PACKAGE_VERSION

__version__ = SHINYLIVE_PACKAGE_VERSION

__all__ = ("decode_shinylive_url", "encode_shinylive_url")
__all__ = ("ShinyliveApp", "url_decode", "url_encode")
43 changes: 15 additions & 28 deletions shinylive/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
import click

from . import _assets, _deps, _export
from ._url import (
create_shinylive_bundle_file,
create_shinylive_bundle_text,
create_shinylive_chunk_contents,
create_shinylive_url,
decode_shinylive_url,
detect_app_language,
write_files_from_shinylive_io,
)
from ._url import ShinyliveApp, detect_app_language, url_decode
from ._utils import print_as_json
from ._version import SHINYLIVE_ASSETS_VERSION, SHINYLIVE_PACKAGE_VERSION

Expand Down Expand Up @@ -562,30 +554,25 @@ def encode(
else:
lang = detect_app_language(app_in)

if "\n" in app_in:
bundle = create_shinylive_bundle_text(app_in, files, lang)
if app == "-":
sl_app = ShinyliveApp.from_text(
app_in, files=files, language=lang, mode=mode, header=not no_header
)
else:
bundle = create_shinylive_bundle_file(app_in, files, lang)
sl_app = ShinyliveApp.from_local(
app_in, files=files, language=lang, mode=mode, header=not no_header
)

if json:
print_as_json(bundle)
print(sl_app.to_json(indent=None))
if not view:
return

url = create_shinylive_url(
bundle,
lang,
mode=mode,
header=not no_header,
)

if not json:
print(url)
print(sl_app.to_url())

if view:
import webbrowser

webbrowser.open(url)
sl_app.view()


@url.command(
Expand Down Expand Up @@ -622,16 +609,16 @@ def decode(url: str, dir: Optional[str] = None, json: bool = False) -> None:
url_in = sys.stdin.read()
else:
url_in = url
bundle = decode_shinylive_url(str(url_in))
sl_app = url_decode(url_in)

if json:
print_as_json(bundle)
print(sl_app.to_json(indent=None))
return

if dir is not None:
write_files_from_shinylive_io(bundle, dir)
sl_app.write_files(dir)
else:
print(create_shinylive_chunk_contents(bundle))
print(sl_app.to_chunk_contents())


# #############################################################################
Expand Down
Loading