Introducing Tapyr: Create and Deploy Enterprise-Ready PyShiny Dashboards with Ease
Tags: datascience, tutorial, python, opensource
Published: 2024-05-05 08:49:00


Are you an R/Shiny user looking to leverage the incredible capabilities of Shiny for Python without sacrificing the familiarity and comfort of your existing tools? 

Introducing [Tapyr](https://github.com/Appsilon/tapyr-template)—our Shiny for Python framework. It brings [Rhino](https://www.appsilon.com/post/rhino-r-package-tutorial)-like capabilities from the R world and more to the Shiny for Python ecosystem, helping you build enterprise-ready applications with ease.

‍

> Curious about Shiny for Python from an R Shiny dev's perspective? [Check out this blog post to learn more.](https://www.appsilon.com/post/pyshiny-demo)
‍

[Tapyr](https://github.com/Appsilon/tapyr-template) is designed as a lightweight template repository for PyShiny projects that offers tools similar to Rhino for R/Shiny. For instance, Tapyr introduces `poetry`, which handles project dependencies much like `renv` in R. This ensures that R users can smoothly adapt to Python without tackling a steep learning curve while adhering to best practices from day 0.

## Key Features of Tapyr

- **Leverage Python Tools:** Tapyr takes advantage of Python’s ecosystem tools, including [ruff](https://github.com/astral-sh/ruff), [pytest](https://docs.pytest.org/en/8.2.x/), and others. 
- **Enterprise-Ready Applications, Made Easy:** The framework is tailored for building robust, scalable, and production-ready applications.
- **Comprehensive Testing with Playwright:** Say goodbye to the hassle of juggling multiple languages for end-to-end testing. [Tapyr leverages Playwright](https://connect.appsilon.com/tapyr-docs/contents/tapyr_features/10_e2e_testing.html?utm_source=community&utm_medium=dev.to&utm_campaign=blog), integrated with pytest, allowing you to write all tests in Python – a streamlined approach that keeps your coding practices consistent and efficient.
- **Static Type Checking with PyRight:** Improve code quality and reduce bugs with [PyRight](https://github.com/microsoft/pyright), a static type checking feature not available in R. This proactive error detection ensures your applications are reliable, before you even start them.

## Complementing Existing Resources

While Posit's [PyShiny templates](https://shiny.posit.co/py/templates/) cater to exploratory data analysis, Tapyr serves a distinct, complementary role by providing a structured repository designed to kickstart your projects. This approach focuses on developing comprehensive, scalable and future-proof applications. 

This not only expands the tools available to data scientists and developers but also helps you to tackle larger, more complex projects effectively.

Tapyr is ideal for **data scientists** (transitioning from R to Python), **developers** familiar with Shiny and Rhino building projects in PyShiny, and **academic researchers** and **enterprise professionals** requiring enterprise-level dashboard frameworks.

## Getting Started with Tapyr

### Using Devcontainer
We recommend using the [Dev Container](https://code.visualstudio.com/docs/remote/containers) configuration with Visual Studio Code (VS Code) or [DevPod](https://devpod.sh/) to ensure a consistent development experience across different computers and environments. It may sound complicated, but it is as easy as a breeze! 

‍

The Dev Container is like a virtual environment with everything you need to work on the project, including all the required software and dependencies.

 

- Install Dev Containers extension if you don’t have it already.

![VS Code Dev Containers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlf857h4ylyu582klrsw.png)

- Clone the repository and start the dev container: You can clone the [Tapyr repository](https://github.com/Appsilon/pyshiny-template) from GitHub or download the source code. 

1. Navigate to the project directory and open the project in VS Code.
2. Select "Reopen in Container" when prompted.
3. If you're prompted to "Reopen in Container," select that option. If not, you can open the Command Palette (`Ctrl+Shift+P` on Windows/Linux, or `Cmd+Shift+P` on Mac) and choose "Remote-Containers: Reopen in Container."
4. If you're using [DevPod](https://devpod.sh/), follow their instructions to start the Devcontainer.
‍

![Reopen in Container](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g88fh3tiojzru4i1bx0s.png)
‍

- Activate the virtual environment: Once the Dev Container is running, you'll need to activate the virtual environment (creating a special workspace where all the project's dependencies are installed).  Run the following command:

```
poetry shell‍
```


![Activate in virtual environment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xr6033hskgzdv371n9av.png)


- **Run the application:** Now you're ready to run the application!  Use this command:

```
shiny run app.py --reload
```

![Run the application](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5w903lbsaqou7fwhnyr.png)


This will start the application and automatically reload it whenever you make changes to the code.


![Tapyr | PyShiny Template](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olqehpzxlmbk3g6pbwjq.png)

- **Execute tests:** To [run tests](https://www.appsilon.com/post/testing-pyshiny-with-playwright) and ensure everything is working correctly, use this command:

```
poetry run pytest
```

![run tests](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rpvyn5lsxz54x66b0oi.png)


**If you prefer to run this locally, [you can do so using Poetry.](https://github.com/Appsilon/tapyr-template?tab=readme-ov-file#setting-up-locally-with-poetry) **

> Struggling with Quality Assurance for your Shiny for Python Dashboards? [Check out this blog post to learn more about leveraging Playwright.](https://www.appsilon.com/post/testing-pyshiny-with-playwright)

### Get Started Today

Dive into Tapyr and start building your enterprise-level applications today! 

[Download Tapyr](https://github.com/Appsilon/tapyr-template), check out [the documentation](https://connect.appsilon.com/tapyr-docs/?utm_source=community&utm_medium=dev.to&utm_campaign=blog), explore its functionalities, and join the community of innovators expanding their PyShiny skillsets.

We value your feedback, so please share your experiences and suggestions to help us improve Tapyr in our [Shiny community](https://go.appsilon.com/shiny4allcommunity). 

‍

> Want to stay up to date with Tapyr and other packages? [Join 4.2k explorers and get the Shiny Weekly Newsletter into your mailbox.](https://go.appsilon.com/shiny-weekly?utm_source=community&utm_medium=dev.to&utm_campaign=blog&utm_content=tapyr)

## FAQs

**Q: Is there a community or support available for Tapyr users?**
**A:** You can create a pull request, open an issue, follow our documentation, and engage with other users in our community to get support, share insights, and contribute to the project's development.
‍

**Q: How is Tapyr different from Posit's PyShiny templates?**
**A:** While Posit's PyShiny templates focus on exploratory data analysis, Tapyr is a framework focused on building comprehensive, scalable PyShiny applications. 


**Q: How does Tapyr compare to other tools like reticulate?**
**A:** While reticulate allows you to call Python from R, Tapyr takes a different approach by providing a streamlined framework for building enterprise-ready applications using Shiny for Python. Since all the code is written in Python, it offers features like static type checking, comprehensive testing with Playwright, and seamless integration with Python ecosystems.