我想通过Docker部署一个由文件ui
、server
和global
组成的shiny 应用程序.所有文件都在文件夹deploy_test
中
我模拟了这个数据集
set.seed(123)
dir.create("deploy_test")
setwd("deploy_test")
mydata_<-data.frame(
gender=c(rep("Male",50),rep("Female",25)),
height=c(rnorm(50,1.70,0.05),rnorm(25,1.65,1))
)
saveRDS(mydata_,file = "mydata_.RDS")
以下是我文件的内容:
1. UI
source("global.R")
dashboardPage(
dashboardHeader(title = "Test of app deployment"),
dashboardSidebar(
selectInput("gender","Gender",as.character(unique(mydata_$gender)))
),
dashboardBody(
fluidRow(
column(6,plotOutput(
"plot1"
)),
column(6,plotOutput(
"plot2"
))
),
fluidRow(
dataTableOutput(
"table"
)
)
)
)
2. SERVER
source("global.R")
function(input, output, session){
output$plot1<-renderPlot(
{
data_<-mydata_%>%filter(
gender==input$gender
)
boxplot(data_$height)
}
)
output$plot2<-renderPlot(
{
data_<-mydata_%>%filter(
gender==input$gender
)
hist(data_$height)
}
)
output$table<-renderDataTable(
{
data_<-mydata_%>%filter(
gender==input$gender
)
data_
}
)
}
3. GLOBAL
library(shinydashboard)
library(shiny)
library(tidyverse)
library(DT)
mydata_<-readRDS("mydata_.RDS")
4. DOCKERFILE
Dockerfile与Shiny的文件夹位于同一个文件夹中:
# Base image
FROM rocker/shiny
#Make a directory in the container
RUN mkdir /home/shiny-app
# Install dependencies
RUN R -e "install.packages(c('tidyverse','shiny','shinydashboard','DT'))"
COPY . /home/shiny-app/
EXPOSE 8180
CMD ["R", "-e", "shiny::runApp('/home/shiny-app')"]
我构建了我的容器,没有任何问题:
docker build -t deploy_test .
当我运行它:
docker run -p 8180:8180 deploy_test
它生成链接: 听http://xxx.x.x.x:xxxx
但当我访问链接时,没有任何东西出现:
我得到:La connexion a échoué