Как создать функцию в блестящем для использования в лапе? - PullRequest
0 голосов
/ 25 июня 2019

Я пытаюсь написать функцию для использования внутри приложения. Однако в блестящем R это кажется нетривиальным, и я постоянно получаю ошибку

Я новичок в глянцевом, но стар в R, и не могу получить четкий набор информации о том, как писать собственные функции в глянцевом.

library(shiny)
library(DT)
library(data.table)

#function that tacks on filename column when file is read
fread_with_file <- function(file){
  read_data <- fread(file)
  data_with_name <- read_data %>% mutate(`File_Name` = file)
  return(data_with_name)
}

# Define UI for application that draws a histogram
ui <- fluidPage(

    # Application title
    titlePanel("File Selection and Join"),

    # Sidebar with a places to input multiple files 
    sidebarLayout(
        sidebarPanel(
           fileInput("oldcsvs", "Upload the Older files", multiple = TRUE),
           fileInput("newcsvs", "Upload the newer files", multiple = TRUE)
            ),
        # Creating tabs for each data set
        mainPanel(
          tabsetPanel(
            type = "tabs",
            tabPanel("Old Data", DT::dataTableOutput("oldcsvs")),
            tabPanel("New Data", DT::dataTableOutput("newcsvs")),
            tabPanel("Joined Data", DT::dataTableOutput("joinedcsvs"))
            )
          )
        )
)


# Define server logic required to draw a histogram
server <- function(input, output) {


  oldCSVData <- reactive({rbindlist(lapply(input$oldcsvs$datapath, fread_with_file))})
  newCSVData <- reactive({rbindlist(lapply(input$newcsvs$datapath, fread_with_file))})

  output$oldcsvs <- DT::renderDataTable({oldCSVData()})
  output$newcsvs <- DT::renderDataTable({newCSVData()})

}

# Run the application 
shinyApp(ui = ui, server = server)

Сообщение об ошибке при компиляции:

Listening on http://127.0.0.1:7822
Warning: Error in makeFunction: argument "expr" is missing, with no default
  51: eval
  50: makeFunction
  49: exprToFunction
  48: reactive
  47: server ********************
Error in makeFunction(body = expr, env = env) : 
  argument "expr" is missing, with no default
...