在ubuntu服务器上使用write.csv时权限被拒绝

时间:2018-02-24 10:00:20

标签: r shiny ubuntu-server rhandsontable

我有这个R应用程序,我用它来同时显示和修改表,使用rHandsontable。它托管在Ubuntu虚拟机上。问题是,当我在计算机上运行代码时,一切正常。但是,当它在我的虚拟机上运行时(Ubuntu 14.04.5 LTS(GNU / Linux 3.13.0-135-通用x86_64)),当我尝试保存它时它会崩溃。我收到以下错误:

  

该应用程序意外退出。

     

诊断信息已转储到JavaScript错误中   控制台。

当我查看日志时,我看到了:

Loading required package: xlsxjars

Listening on http://127.0.0.1:53183
Warning in file(file, ifelse(append, "a", "w")) :
  cannot open file 'listes/liste_traiteur.csv': Permission denied
Warning: Error in file: cannot open the connection
Stack trace (innermost first):
    62: file
    61: write.table
    60: eval
    59: eval
    58: eval.parent
    57: write.csv
    56: observerFunc [/srv/shiny-server/app.R#187]
     1: runApp

以下是代码:

# before UI and server 
filename <- as.character("liste_traiteur")
file <- paste0(filename, ".csv")
liste_menu <- read.csv(file = file, header = TRUE, sep = ",")

fname <- file # R object data frame stored as ASCII text
values <- list() 
setHot <- function(x) values[["hot"]] <<- x 

# inside the server
      observe({ 
      input$saveBtn # update csv file each time the button is pressed
      if (!is.null(values[["hot"]])) { # if there's a table input
        write.csv(values[["hot"]], fname) # overwrite the temporary database file
        write.csv(x = values[["hot"]], file = fname, row.names = FALSE) # overwrite the csv
        shinyjs::hide("modification")
        shinyjs::show("modif_reussie")
        shinyjs::reset("form")
        liste_menu <- read.csv(file = fname, header = TRUE, stringsAsFactors = FALSE)
      }
    })
      output$hot <- renderRHandsontable({ 

        if (!is.null(input$hot)) { # if there is an rhot user input...
          DF <- hot_to_r(input$hot) # convert rhandsontable data to R object and store in data frame
          setHot(DF) # set the rhandsontable values

        } else {
          DF <- read.csv(file = fname, header = TRUE, stringsAsFactors = FALSE) # else pull table from the csv (default)
          setHot(DF) # set the rhandsontable values
        }

      rhandsontable(DF) %>% # actual rhandsontable object
        hot_table(highlightCol = TRUE, highlightRow = TRUE, readOnly = FALSE) %>%
        hot_col("Item", readOnly = FALSE) %>%
        hot_col("Prix", readOnly = FALSE)
    })

fname是我们正在读取的文件,然后在用户使用显示的rhandsontable对象修改它时进行覆盖。它在UI中显示如下:

  tabPanel("Liste de prix", 
           fluidPage(
             shinyjs::useShinyjs(), 
             shinyjs::inlineCSS(appCSS),
             fluidRow(
               div(
                 id = "modification",
                 column(12,
           rHandsontableOutput("hot"),
           br(),
           actionButton("saveBtn", "Enregistrer", icon = icon("floppy-o")))
               )),
           fluidRow(
                    shinyjs::hidden(
                      div(
                        id = "modif_reussie",
                        column(12,
                        h3("La modification a été effectuée avec succès."),
                        actionLink("autre_modif", "Revenir à la page")
                      ))))
           ))

当actionButton“saveBtn”被执行时,会发生错误。交互式表格中的代码最初来自:

https://gist.github.com/cxbonilla/f49a2c7dbcfa23e6931b83838fad892d

有人可以帮忙吗?这真的很奇怪,因为我的应用程序的另一部分实际上是在我的计算机和VM上读取和写入.csv。但它使用基本的R函数而不是rHandsontable。所以我不太了解这里发生了什么。

谢谢!

1 个答案:

答案 0 :(得分:0)

您闪亮的服务器无权将文件保存到所需的文件夹。 这样的事情可能会有所帮助:

sudo chown shiny:shiny /var/shiny-server/myfolder
相关问题