Невозможно запустить приложение, используя функцию editTable - PullRequest
0 голосов
/ 26 июня 2019

Каждый раз, когда я пытаюсь запустить приложение, используя некоторый пример кода кода, приложение запускается при запуске, заявляя, что R не распознает аргументы внутри editTable, такие как outdir или outfilename. Или приложение вообще не запускается и возвращает эту ошибку

"Ошибка в perfectApp (ui = ui, server = server): объект 'server' не найден."

Кто-нибудь еще имел эту проблему раньше?

Пример кода, который я использую, можно найти здесь: http://stla.github.io/stlapblog/posts/shiny_editTable.html

Я также добавлю свой модифицированный код ниже.

библиотека (rhandsontable) библиотека (блестящий)

editTable <- функция (DF, outdir = getwd ("/ Users / gabrieldmay / Library / Mobile Документы / com ~ apple ~ CloudDocs / Midnight Strategies / Apps / Charlie Nation "), outfilename = "newDF.csv") {</p>

DF <- data.frame (Значение = 1:10, Статус = ИСТИНА, Имя = ПИСЬМА [1:10], Date = seq (from = Sys.Date (), by = "days", length.out = 10), stringsAsFactors = FALSE) } </p>

ui <- shinyUI(fluidPage(

titlePanel("Edit and save a table"),
sidebarLayout(
  sidebarPanel(
    helpText("Shiny app based on an example given in the rhandsontable 
package.", 
             "Right-click on the table to delete/insert rows.", 
             "Double-click on a cell to edit"),

    wellPanel(
      h3("Table options"),
      radioButtons("useType", "Use Data Types", c("TRUE", "FALSE"))
    ),
    br(), 

    wellPanel(
      h3("Save table"), 
      div(class='row', 
          div(class="col-sm-6", 
              actionButton("save", "Save")),
          div(class="col-sm-6",
              radioButtons("fileType", "File type", c("ASCII", "RDS")))
      )
    )

  ),

  mainPanel(
    wellPanel(
      uiOutput("message", inline=TRUE)
    ),

    actionButton("cancel", "Cancel last action"),
    br(), br(), 

    rHandsontableOutput("hot"),
    br(),

    wellPanel(
      h3("Add a column"),
      div(class='row', 
          div(class="col-sm-5", 
              uiOutput("ui_newcolname"),
              actionButton("addcolumn", "Add")),
          div(class="col-sm-4", 
              radioButtons("newcolumntype", "Type", c("integer", 
"double", "character"))),
          div(class="col-sm-3")
      )
    )

  )
)

)) * * тысяча двадцать-одна

server <- shinyServer(function(input, output) {

values <- reactiveValues()

## Handsontable
observe({
  if (!is.null(input$hot)) {
    values[["previous"]] <- isolate(values[["DF"]])
    DF = hot_to_r(input$hot)
  } else {
    if (is.null(values[["DF"]]))
      DF <- DF
    else
      DF <- values[["DF"]]
  }
  values[["DF"]] <- DF
})

output$hot <- renderRHandsontable({
  DF <- values[["DF"]]
  if (!is.null(DF))
    rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = 
"all")
})

## Save 
observeEvent(input$save, {
  fileType <- isolate(input$fileType)
  finalDF <- isolate(values[["DF"]])
  if(fileType == "ASCII"){
    dput(finalDF, file=file.path(outdir, sprintf("%s.txt", outfilename)))
  }
  else{
    saveRDS(finalDF, file=file.path(outdir, sprintf("%s.rds", 
outfilename)))
  }
}
)

## Cancel last action    
observeEvent(input$cancel, {
  if(!is.null(isolate(values[["previous"]]))) values[["DF"]] <- 
isolate(values[["previous"]])
})

## Add column
output$ui_newcolname <- renderUI({
  textInput("newcolumnname", "Name", sprintf("newcol%s", 
1+ncol(values[["DF"]])))
})
observeEvent(input$addcolumn, {
  DF <- isolate(values[["DF"]])
  values[["previous"]] <- DF
  newcolumn <- eval(parse(text=sprintf('%s(nrow(DF))', 
isolate(input$newcolumntype))))
  values[["DF"]] <- setNames(cbind(DF, newcolumn, 
stringsAsFactors=FALSE), c(names(DF), isolate(input$newcolumnname)))
})

## Message
output$message <- renderUI({
  if(input$save==0){
    helpText(sprintf("This table will be saved in folder \"%s\" once you 
press the Save button.", outdir))
  }else{
    outfile <- ifelse(isolate(input$fileType)=="ASCII", "table.txt", 
 "table.rds")
    fun <- ifelse(isolate(input$fileType)=="ASCII", "dget", "readRDS")
    list(helpText(sprintf("File saved: \"%s\".", file.path(outdir, 
 outfile))),
         helpText(sprintf("Type %s(\"%s\") to get it.", fun, outfile)))
  }
})

})

## run app 
shinyApp(ui = ui, server = server)
...