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 ----
2
4
app_dir <- tempfile()
3
5
dir.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
27
6
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" )
30
11
)
31
12
32
- # Export the app
13
+ # # Export the app ----
33
14
shinydocker :: export(app_dir , run = TRUE , detach = TRUE )
34
15
35
16
# Stop the container
36
- stop_container(app_dir )
17
+ shinydocker :: stop_container(app_dir )
37
18
38
19
# Restart the container:
39
20
shinydocker :: run_container(app_dir , detach = TRUE )
@@ -44,4 +25,4 @@ shinydocker::run_container(app_dir, detach = TRUE)
44
25
# Build Docker image
45
26
# shinydocker::build_image(app_dir)
46
27
# Run the containerized app
47
- # shinydocker::run_container(app_dir, detach = TRUE)
28
+ # shinydocker::run_container(app_dir, detach = TRUE)
0 commit comments