generated from Appsilon/tapyr-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c2534f6
Showing
31 changed files
with
2,834 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/python | ||
{ | ||
"name": "Python 3", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"image": "mcr.microsoft.com/devcontainers/python:3.10-bullseye", | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
"features": { | ||
"ghcr.io/devcontainers-contrib/features/poetry:2": {}, | ||
"ghcr.io/devcontainers/features/node:1": {} | ||
}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
"postCreateCommand": "poetry install && poetry run playwright install --with-deps", | ||
|
||
// Configure tool-specific properties. | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"ms-python.python", | ||
"ms-toolsai.jupyter", | ||
"charliermarsh.ruff", | ||
"streetsidesoftware.code-spell-checker", | ||
"tamasfe.even-better-toml", | ||
"ryanluker.vscode-coverage-gutters" | ||
] | ||
} | ||
} | ||
|
||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Validate Tapyr App' | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout (GitHub) | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run quality checks | ||
uses: devcontainers/[email protected] | ||
with: | ||
runCmd: ./quality_checks.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: pre-commit | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
- uses: pre-commit/[email protected] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
__pycache__ | ||
.ipynb_checkpoints | ||
.DS_Store | ||
|
||
# Code coverage | ||
lcov.info | ||
.coverage | ||
|
||
# Results of playwright tests with tracing | ||
test-results/ | ||
|
||
# Files from playwright installed with npm | ||
node_modules | ||
package-lock.json | ||
package.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
exclude: ^data/records\.parquet$ | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.4.1 | ||
hooks: | ||
- id: ruff | ||
args: [ --fix ] | ||
- id: ruff-format |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Tapyr - Shiny for Python Application Template<a href="https://appsilon.github.io/tapyr-template/"><img src="www/images/tapyr.png" align="right" alt="Tapyr logo" style="height: 140px;"></a> | ||
|
||
> Create and deploy enterprise-ready PyShiny dashboards with ease. | ||
# WIP: Not the final version of README. | ||
|
||
## Introduction | ||
|
||
Tapyr is designed for data scientists and developers seeking a seamless transition from development to deployment, this template uses `poetry` for dependency management and `pytest`/`playwright` for comprehensive app validation/testing/quality assurance. | ||
Ideal for projects aiming for high-quality code and efficient deployment on Posit Connect. | ||
|
||
## Docs | ||
|
||
For comprehensive documentation, please visit our [documentation TODO](TODO). | ||
|
||
## Getting Started | ||
|
||
Check out our get started with `tapyr` [blog post TODO](TOOD). | ||
|
||
### Using Devcontainer | ||
|
||
To ensure a consistent development experience across all environments, we recommend using the [devcontainer](https://code.visualstudio.com/docs/remote/containers) configuration with Visual Studio Code or DevPod for container-based development. | ||
|
||
1. **Start the Devcontainer**: Open the project in VS Code and select "Reopen in Container" when prompted, or use the Command Palette (`Ctrl+Shift+P`) and choose "Remote-Containers: Reopen in Container". Alternatively, use [DevPod](https://devpod.sh/) following their instructions. | ||
2. **Activate the virtual environment**: | ||
```sh | ||
poetry shell | ||
``` | ||
3. **Run the application**: | ||
```sh | ||
shiny run app.py --reload | ||
``` | ||
4. **Execute tests**: | ||
```sh | ||
poetry run pytest | ||
``` | ||
|
||
*Note*: The Devcontainer might limit some `playwright` features, such as `codegen`. For full functionality, consider a local setup. | ||
|
||
### Setting Up Locally with Poetry | ||
|
||
For developers preferring a local setup without Devcontainer: | ||
|
||
1. **Install pipx**: Ensure pipx is installed for managing isolated CLI apps. | ||
2. **Install Poetry**: | ||
```sh | ||
pipx install poetry | ||
``` | ||
3. **Clone the repository** and navigate to it. | ||
4. **Install dependencies**: | ||
```sh | ||
poetry install | ||
playwright install | ||
``` | ||
|
||
*Attention*: Follow any additional steps prompted by `playwright install`. | ||
|
||
### Deployment on Posit Connect | ||
|
||
Deploy your application to Posit Connect by: | ||
|
||
1. **Exporting your API Key**: | ||
```sh | ||
export CONNECT_API_KEY="your_api_key_here" | ||
``` | ||
2. **Configuring Posit Connect**: | ||
```sh | ||
rsconnect add \ | ||
--api-key $CONNECT_API_KEY \ | ||
--server <MY_CONNECT_URL> \ | ||
--name <SERVER_NAME> | ||
``` | ||
3. **Deploying**: | ||
```sh | ||
rsconnect deploy shiny -t "Tapyr App" . | ||
``` | ||
|
||
Replace placeholders with your server URL, server name, and API key. Verify the deployment on Posit Connect for successful upload. | ||
|
||
--- | ||
|
||
Developed with :heart: at [Appsilon](https://appsilon.com). | ||
Get in touch: <[email protected]>. | ||
|
||
Want to stay up to date with Tapyr and other packages? Join 4,2k explorers and get the [📧 Shiny Weekly Newsletter](https://go.appsilon.com/shiny-weekly?utm_source=community&utm_medium=github&utm_content=tapyr) into your mailbox and check our [Slack community](https://go.appsilon.com/shiny4allcommunity). | ||
|
||
Explore the [Rhinoverse](https://rhinoverse.dev) - a family of R packages built around [Rhino](https://appsilon.github.io/rhino/)! | ||
|
||
Appsilon is a | ||
[**Posit (formerly RStudio) Full Service Certified Partner**](https://www.rstudio.com/certified-partners/). | ||
|
||
<a href="https://appsilon.com/careers/"> | ||
<img src="https://raw.githubusercontent.com/Appsilon/website-cdn/gh-pages/WeAreHiring1.png" alt="We are hiring!"> | ||
</a> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
from loguru import logger | ||
from shiny import App, ui | ||
|
||
from tapyr_template.settings import AppSettings | ||
from tapyr_template.view.root import get_dashboard_ui, server | ||
|
||
# Setup settings and logger | ||
app_settings = AppSettings() | ||
logger.remove() | ||
logger.add(sys.stderr, level=app_settings.log_level) | ||
|
||
# Combine clean shiny UI with CSS and external resources | ||
ui_with_css = ui.TagList(ui.tags.link(href="style.css", rel="stylesheet"), get_dashboard_ui()) | ||
|
||
app_dir = Path(__file__).parent | ||
app = App(ui_with_css, server, static_assets=app_dir / "www") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from tapyr_template.logic.utils import divide" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"divide(10, 2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# divide(10, 0) # raises ZeroDivisionError" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "pyshiny-template-AF2zGnGe-py3.12", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.