...Hi,
This is my first post on here, I've tried to follow the guidelines, but please let me know if there's any more info I can provide or any posting protocol faux-pas in any of the below.
I've built a shiny app that relies on the xlsx package in R to create an excel workbook that the user can then download. The app runs fine locally, but in attempting to deploy it in a docker container on a linux VM I'm having a lot of trouble.
A basic example of the app is as follows
server.R
library(xlsx)
savefile <- function(filename){
a <- data.frame(a = c(2,4,7), b = c("blue", "red", "yellow"))
b <- data.frame(a = c(5,8,9), b = c("dog", "cat", "monkey"))
# Create a results file
wb <- createWorkbook(type = "xlsx")
# Create excel output Sheets
sheet_data1 <- createSheet(wb, sheetName = "Data")
sheet_data2 <- createSheet(wb, sheetName = "Data2" )
#add data to the first sheet
addDataFrame(a, sheet_data1, startRow=1, startColumn=1)
#add data to the second sheet
addDataFrame(b, sheet_data2, startRow=1, startColumn=1)
#save the workbook
saveWorkbook(wb, paste0("temp/",filename,".xlsx"))
}
function(input, output, session) {
session$onSessionEnded(function(){
file.remove("temp/test file.xlsx")
})
output$downloadData <- downloadHandler(filename = function(){paste0(input$downloadName,".xlsx")},
content = function(file){
file.copy("temp/test file.xlsx", file)
})
observeEvent(input$sensoryCall, {
savefile("test file")
})
}
and ui.R
library(shinydashboard)
dashboardPage(skin="purple",
dashboardHeader(title = "Analysis"),
dashboardSidebar(
sidebarMenu(
menuItem("Run Analysis", tabName = "analyse", icon = icon("flash")),
menuItem("Export Results", tabName = "export", icon = icon("download"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "analyse",
h2("Run Sensory Analysis"),
fluidRow(
box(actionButton("sensoryCall", "Run Analysis", class='btn-primary'))
)
),
tabItem(tabName = "export",
h2("Export Results to Excel"),
fluidRow(
box(textInput("downloadName", "Specify desired name of results file"),
downloadButton("downloadData", "Download Results"))
)
)
)
)
)
It took a while to get the rJava dependency sorted with the dockerfile set-up, I'd describe myself as a relative noob when it comes to linux and docker, but I've got it to a point where the R package checking seems to work for both rJava and xlsx with the following dockerfile set up, although there are a few warnings that come up in the build log, so this could be the route of the issue, but I'm at a stage where the messages and what I could do to fix them are well above my level of understanding.
FROM rocker/shiny-verse:latest
#Install wget and gnupg
RUN apt-get update && apt-get install -my wget gnupg
RUN apt-get update && apt-get install -y libbz2-dev liblzma-dev libicu-dev
#Install oracle java 8
RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections \
&& echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list \
&& echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 \
&& apt-get update \
&& apt-get install oracle-java8-installer -y
# clean local repository
RUN apt-get clean
# set up JAVA_HOME
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
RUN R CMD javareconf
#Install R packages
RUN R -e "install.packages(c('shiny', 'shinydashboard', 'rJava', 'xlsx'))"
When I click on the run analysis button in the containerised app, I get the following error message " Error: java.io.FileNotFoundException: test file.xlsx (Permission denied)" so I guess what's happening is that the app does not have permission to save the results file, but is there an easy way to either grant these permissions, or is there a better workaround that I could look to apply?
Thanks in advance for any suggestions offered