Skip to content

Commit d319788

Browse files
committed
Refine README.Rmd
1 parent 95d0f3e commit d319788

File tree

3 files changed

+349
-109
lines changed

3 files changed

+349
-109
lines changed

DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ URL: https://r-pkg.thecoatlessprofessor.com/shinydocker/, https://github.com/coa
1515
BugReports: https://github.com/coatless-rpkg/shinydocker/issues
1616
License: AGPL (>= 3)
1717
SystemRequirements: Docker (>= 28.0.0)
18+
Depends: R (>= 4.4)
1819
Imports:
1920
yaml,
2021
processx,

README.Rmd

+174-56
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ output: github_document
33
---
44

55
<!-- README.md is generated from README.Rmd. Please edit that file -->
6-
76
```{r, include = FALSE}
87
knitr::opts_chunk$set(
98
collapse = TRUE,
@@ -13,21 +12,20 @@ knitr::opts_chunk$set(
1312
)
1413
```
1514

16-
17-
> [!IMPORTANT]
18-
>
19-
> This package is currently in the prototype/experimental stage. It is not yet
20-
> available on CRAN and may have bugs or limitations.
21-
22-
# shinydocker <img src="man/figures/shinydocker-animated-logo.svg" align="right" height="139" />
15+
# shinydocker <a href="https://r-pkgs.thecoatlessprofessor.com/shinydocker/"><img src="man/figures/shinydocker-animated-logo.svg" align="right" height="138" alt="hex logo for shinydocker" /></a>
2316

2417
<!-- badges: start -->
2518
[![R-CMD-check](https://github.com/coatless-rpkg/shinydocker/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/coatless-rpkg/shinydocker/actions/workflows/R-CMD-check.yaml)
2619
![Prototype](https://img.shields.io/badge/Status-Prototype-orange)
2720
![Experimental](https://img.shields.io/badge/Status-Experimental-blue)
2821
<!-- badges: end -->
2922

30-
`shinydocker` is an R package that streamlines the process of containerizing Shiny applications, supporting both R and Python Shiny apps.
23+
`shinydocker` simplifies containerizing Shiny applications by automatically generating Docker configurations, building images, and managing containers. It supports both R and Python Shiny apps with intelligent detection of app type and dependencies.
24+
25+
> [!IMPORTANT]
26+
>
27+
> This package is currently in the prototype/experimental stage. It is not yet
28+
> available on CRAN and may have bugs or limitations.
3129
3230
## Installation
3331

@@ -40,105 +38,225 @@ You can install the development version of `shinydocker` from GitHub with:
4038
remotes::install_github("coatless-rpkg/shinydocker")
4139
```
4240

43-
You will also need to have Docker installed on your system. You can download Docker from the [official website](https://www.docker.com/products/docker-desktop). You do not need to
44-
log in to Docker to use `shinydocker`.
41+
### Prerequisites
42+
43+
- R (>= 4.4.0)
44+
- [Docker](https://www.docker.com/products/docker-desktop) installed and running (no login required)
45+
- Optionally, [Docker Compose](https://docs.docker.com/compose/install/) for more advanced container management
4546

46-
## Using shinydocker
47+
## Quick Start
4748

48-
The package provides a set of functions to automate the process, as well as options for advanced configuration.
49+
With `shinydocker`, you can containerize your Shiny app in just a few lines of code.
50+
Here's two ways to get started with the package!
4951

50-
### Exporting a Shiny App to Docker
52+
### One-Command Export
5153

52-
The `export()` function allows you to convert a Shiny application into a docker
53-
containerized application.
54+
The simplest way to containerize a Shiny app is to use the `shinydocker::export()` function:
5455

5556
```{r}
56-
#| label: export-shiny-app-to-docker-generic
57+
#| label: quick-export
5758
#| eval: false
58-
# Automated export: configures, builds, and optionally runs the container
59-
export("path/to/your/shinyapp", run = TRUE)
59+
library(shinydocker)
60+
61+
# Export app to Docker with a single command (detects app type automatically)
62+
shinydocker::export("path/to/your/shinyapp", run = TRUE)
6063
```
6164

62-
For example, to convert the "Hello World" Shiny app from the `{shiny}` package
63-
into a standalone Electron app:
65+
### Example: Converting the "Hello World" Shiny App
66+
67+
To get started, let's convert the classic "Hello World" Shiny app to a Docker container:
6468

6569
```{r}
66-
#| label: export-shiny-app-to-docker-hello-world
70+
#| label: export-hello-world
6771
#| eval: false
68-
# Copy "Hello World" from `{shiny}`
69-
system.file("examples", "01_hello", package="shiny") |>
70-
fs::dir_copy("myapp", overwrite = TRUE)
72+
# Copy the Hello World example from the shiny package
73+
app_dir <- "hello_world_app"
74+
system.file("examples", "01_hello", package = "shiny") |>
75+
fs::dir_copy(app_dir, overwrite = TRUE)
7176
72-
shinydocker::export("myapp", run = TRUE)
77+
# Export to Docker and run
78+
shinydocker::export(app_dir, run = TRUE, detach = TRUE)
79+
80+
# The console will show a URL where you can access your containerized app
81+
82+
# Stop the container when done
83+
shinydocker::stop_container()
7384
```
7485

86+
### Step-by-Step Workflow
7587

76-
### Manually Dockerizing a Shiny App
88+
For more control over the containerization process:
7789

7890
```{r}
79-
#| label: dockerize-a-shiny-app
91+
#| label: step-by-step
8092
#| eval: false
8193
library(shinydocker)
8294
83-
# Path to your Shiny app
84-
shiny_app_path <- "path/to/your/shinyapp"
95+
# 1. Create Docker configuration
96+
shinydocker::dockerize("path/to/your/shinyapp")
8597
86-
# Create Docker configuration for a Shiny app
87-
dockerize(shiny_app_path)
98+
# 2. Build Docker image
99+
shinydocker::build_image("path/to/your/shinyapp")
88100
89-
# Build a Docker image
90-
build_image(shiny_app_path)
101+
# 3. Run the container on port 8080
102+
shinydocker::run_container("path/to/your/shinyapp", port = 8080, detach = TRUE)
91103
92-
# Run the container
93-
run_container(shiny_app_path)
104+
# 4. When done, stop the container
105+
shinydocker::stop_container("path/to/your/shinyapp")
94106
```
95107

96-
### Diagnostic Tools
108+
109+
### R or Python Shiny Apps
110+
111+
`shinydocker` automatically detects and containerizes either R or Python Shiny apps
112+
by detecting the app type and dependencies in the app directory. The app type
113+
is determined by the presence of either a `app.R`/`server.R`/`ui.R` file for R Shiny apps
114+
or a `app.py`/`server.py`/`ui.py` file for Python Shiny apps. Dependencies are detected
115+
automatically from the app source for R Shiny apps and a `requirements.txt` file for Python Shiny apps.
116+
117+
Therefore, you can use the same `export()` function for both R and Python Shiny apps:
97118

98119
```{r}
99-
#| label: diagnostic-tools
120+
#| label: python-shiny
100121
#| eval: false
101-
# Check Docker environment
102-
sitrep_docker()
103-
104-
# Analyze app containerization readiness
105-
sitrep_app_conversion("path/to/your/shinyapp")
122+
shinydocker::export("path/to/your/python_shinyapp", run = TRUE)
106123
```
107124

108125

126+
### Examples
127+
128+
More examples are available in the package's [`inst/examples/shiny`](inst/examples/shiny) directory.
109129

110130
## Advanced Configuration
111131

112-
### Custom Dockerfile
132+
For more advanced use cases, you can customize the containerization process with additional options.
133+
You can pass these options to the `dockerize()` function.
134+
135+
### Environment Variables
136+
137+
Pass sensitive information or configuration to your Shiny app:
138+
139+
```{r}
140+
#| label: env-vars
141+
#| eval: false
142+
# Add environment variables to the container
143+
shinydocker::dockerize("path/to/your/shinyapp",
144+
env_vars = c(
145+
API_KEY = "your-secret-key",
146+
DB_HOST = "database.example.com",
147+
LOG_LEVEL = "INFO"
148+
))
149+
```
150+
151+
### Custom Port Mapping
152+
153+
```{r}
154+
#| label: custom-port
155+
#| eval: false
156+
# Run the container on a specific port
157+
shinydocker::run_container("path/to/your/shinyapp", port = 3000)
158+
```
159+
160+
### Custom Dockerfile Template
161+
162+
For advanced customization, you can provide your own Dockerfile template:
113163

114164
```{r}
115165
#| label: custom-dockerfile
116166
#| eval: false
117167
# Use a custom Dockerfile template
118-
dockerize("path/to/your/shinyapp",
168+
shinydocker::dockerize("path/to/your/shinyapp",
119169
custom_dockerfile = "path/to/custom/Dockerfile")
120170
```
121171

122-
### Environment Variables
172+
## Diagnostic Tools
173+
174+
`shinydocker` provides two situation report (sitrep) functions that offer
175+
diagnostic information about your Docker environment and app containerization readiness.
176+
177+
### Check Docker Environment
178+
179+
180+
```{r}
181+
#| label: check-docker
182+
#| eval: false
183+
# Check if Docker is correctly set up
184+
shinydocker::sitrep_docker()
185+
```
186+
187+
### Analyze App Containerization Readiness
123188

124189
```{r}
125-
#| label: dockerize
190+
#| label: check-app
126191
#| eval: false
127-
# Set environment variables during containerization
128-
dockerize("path/to/your/shinyapp",
129-
env_vars = c(API_KEY = "your-secret-key"))
192+
# Check if your app is ready for containerization
193+
shinydocker::sitrep_app_conversion("path/to/your/shinyapp")
130194
```
131195

132-
## Cleanup and Management
196+
## Container Management
197+
198+
`shinydocker` provides functions to manage your Shiny app containers so that
199+
you can start, stop, and clean up containers with ease without needing to remember
200+
Docker commands or jump into terminal.
201+
202+
### Running Containers
133203

134204
```{r}
135-
#| label: cleanup-and-management
205+
#| label: run-containers
136206
#| eval: false
137-
# Stop a specific container
138-
stop_containers("path/to/your/shinyapp")
207+
# Run with docker-compose (if available)
208+
shinydocker::run_container("path/to/your/shinyapp", docker_compose = TRUE)
209+
210+
# Run with plain docker
211+
shinydocker::run_container("path/to/your/shinyapp", docker_compose = FALSE)
212+
```
213+
214+
### Stopping Containers
139215

140-
# Clean up Docker containers and images
141-
cleanup_containers(remove_images = TRUE)
216+
```{r}
217+
#| label: stop-containers
218+
#| eval: false
219+
# Stop container for a specific app
220+
shinydocker::stop_container("path/to/your/shinyapp")
221+
222+
# Stop all running containers
223+
shinydocker::stop_container()
224+
```
225+
226+
### Cleanup
227+
228+
```{r}
229+
#| label: cleanup
230+
#| eval: false
231+
# Remove containers for a specific app
232+
shinydocker::cleanup_containers("path/to/your/shinyapp")
233+
234+
# Remove all shinydocker containers and images
235+
shinydocker::cleanup_containers(remove_images = TRUE, force = TRUE)
236+
237+
# Clean up and run docker system prune
238+
shinydocker::cleanup_containers(prune = TRUE)
239+
```
240+
241+
242+
## Troubleshooting
243+
244+
If you encounter issues:
245+
246+
1. Run `shinydocker::sitrep_docker()` to check Docker installation
247+
2. Run `shinydocker::sitrep_app_conversion("path/to/your/shinyapp")` to analyze app issues
248+
3. Check for port conflicts with `shinydocker::is_port_available(3838)`
249+
250+
Need more help? Consider opening an [issue](https://github.com/coatless-rpkg/shinydocker/issues/new) on the repository.
251+
252+
## Citation
253+
254+
If you use `shinydocker` in your research or project, please consider citing it:
255+
256+
```{r}
257+
#| label: citation
258+
#| eval: false
259+
citation("shinydocker")
142260
```
143261

144262
## License

0 commit comments

Comments
 (0)