1- # Create a simple Shiny for Python app
1+ # Quick demo of containerizing a simple Shiny for Python app
2+
3+ # # Setup a temporary directory that gets destructed after the session ----
24app_dir <- tempfile()
35dir.create(app_dir )
4- writeLines(
5- ' from shiny import App, ui, render
6- import numpy as np
7- import matplotlib.pyplot as plt
8-
9- app_ui = ui.page_fluid(
10- ui.panel_title("Hello Docker"),
11- ui.layout_sidebar(
12- ui.sidebar(
13- ui.input_slider("obs", "Number of observations:", min=1, max=1000, value=500)
14- ),
15- ui.output_plot("distPlot")
16- )
17- )
18-
19- def server(input, output, session):
20- @output
21- @render.plot
22- def distPlot():
23- data = np.random.normal(size=input.obs())
24- fig, ax = plt.subplots()
25- ax.hist(data)
26- return fig
276
28- app = App(app_ui, server)' ,
29- file.path(app_dir , " app.py" )
7+ # # Create a simple Shiny for Python app from a template ----
8+ writeLines(
9+ readLines(system.file(" examples" , " shiny" , " python" , " hello-docker-plain" , " app.py" , package = " shinydocker" )),
10+ file.path(app_dir , " app.py" )
3011)
3112
32- # Export the app
13+ # # Export the app ----
3314shinydocker :: export(app_dir , run = TRUE , detach = TRUE )
3415
3516# Stop the container
36- stop_container(app_dir )
17+ shinydocker :: stop_container(app_dir )
3718
3819# Restart the container:
3920shinydocker :: run_container(app_dir , detach = TRUE )
@@ -44,4 +25,4 @@ shinydocker::run_container(app_dir, detach = TRUE)
4425# Build Docker image
4526# shinydocker::build_image(app_dir)
4627# Run the containerized app
47- # shinydocker::run_container(app_dir, detach = TRUE)
28+ # shinydocker::run_container(app_dir, detach = TRUE)
0 commit comments