LoginSignup
1
3

More than 3 years have passed since last update.

R言語のFW ShinyをDockerでサクッと構築する

Last updated at Posted at 2020-02-10

概要

タイトルまんま

ディレクトリ構成

r-shiny-docker
├── apps
│   ├── appdir
│   │   ├── server.R
│   │   └── ui.R
│   └── index.html
└── docker-compose.yml

docker-compose.yml

docker-compose.yml
version: "3"
services: 
  shiny:
    image: rocker/shiny:3.4.4
    ports: 
      - 3838:3838
    volumes: 
      - "./apps:/srv/shiny-server"

server.R

server.R
#
# This is the server logic of a Shiny web application. You can run the 
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
# 
#    http://shiny.rstudio.com/
#

library(shiny)

# Define server logic required to draw a histogram
shinyServer(function(input, output) {
   
  output$distPlot <- renderPlot({
    
    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
    
  })
})

ui.R

ui.R
#
# This is the user-interface definition of a Shiny web application. You can
# run the application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
# 
#    http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
shinyUI(fluidPage(
  
  # Application title
  titlePanel("Old Faithful Geyser Data"),
  
  # Sidebar with a slider input for number of bins 
  sidebarLayout(
    sidebarPanel(
       sliderInput("bins",
                   "Number of bins:",
                   min = 1,
                   max = 50,
                   value = 30)
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
       plotOutput("distPlot")
    )
  )
))

index.html

index.html
hello

接続

http://localhost:3838/
Image from Gyazo

http://localhost:3838/appdir/
Image from Gyazo

参考

  • (rocker-org/shiny)[https://github.com/rocker-org/shiny]
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3