Ошибка публикации блестящего приложения: app.R не возвратил блестящий объект - PullRequest
0 голосов
/ 03 января 2019

Я создаю приложение с простой моделью ML, рабочий процесс выглядит следующим образом:

1) Чтение файла.2) Создайте модель 3) Составьте прогноз и значение переменной

Локально, приложение работает нормально:

enter image description here

Но когдаЯ пытаюсь опубликовать приложение, я получаю следующую ошибку:

Error in value[[3L]](cond) : app.R did not return a shiny.appobj object.
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Ejecución interrumpida

enter image description here

Ошибка не говорит мне, это полный код:

library(shiny)
library(readxl)
library(tidyverse)
library(xgboost)
library(caret)
library(iml)


#### UI


ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose CSV File",
                accept = c(
                  "text/csv",
                  "text/comma-separated-values,text/plain",
                  ".csv")
      ),
      tags$hr(),
      checkboxInput("header", "Header", TRUE)
    ),
    mainPanel(
      plotOutput("plot2", click = "plot_brush"),
      plotOutput("plot1", click = "plot_brush")
    )
  )
)

server <- function(input, output) {
  # create mydata as a reactiveVal so that it can be edited everywhere
  mydata = reactiveVal()
  model <- reactiveValues()


  # reactive block is changed with an observe that allows mydata to be updated
  # on change of data
  observe({
    req(input$file1, input$header, file.exists(input$file1$datapath))
    data = read.csv(input$file1$datapath, header = input$header)
    mydata(data)
  })


  output$contents <- renderTable({
    req(mydata())
    #mydata()
  })


  ### test
  xgb_trcontrol = trainControl(
    method = "cv",
    number = 5,
    allowParallel = TRUE,
    verboseIter = FALSE,
    returnData = FALSE
  )


  xgbGrid <- expand.grid(nrounds = c(10,14),  # this is n_estimators in the python code above
                         max_depth = c(10, 15, 20, 25),
                         colsample_bytree = seq(0.5, 0.9, length.out = 5),
                         ## The values below are default values in the sklearn-api.
                         eta = 0.1,
                         gamma=0,
                         min_child_weight = 1,
                         subsample = 1
  )




  observe({

    if ('data.frame' %in% class(mydata()) & !'predicted' %in% names(mydata())){
      set.seed(0)
      xgb_model = train(
        select(mydata(),"LotArea","YrSold"), as.vector(t(mydata()["SalePrice"])),
        trControl = xgb_trcontrol,
        tuneGrid = xgbGrid,
        method = "xgbTree"
      )

      predicted = predict(xgb_model, select(mydata(),"LotArea","YrSold"))
      data = mydata()
      data["predicted"] = predicted
      mydata(data)
    }


    #xgb_model



  })

  output$plot1 <- renderPlot({
    data = mydata()
    # this is here to prevent premature triggering of this ggplot.
    # otherwise you'll get the "object not found" error
    if('predicted' %in% names(data)){
      ggplot(mydata(), aes(x=predicted, y=SalePrice)) + geom_point()
    }
  })

  output$plot2 <- renderPlot({
    data = mydata()
    # this is here to prevent premature triggering of this ggplot.
    # otherwise you'll get the "object not found" error
    if('predicted' %in% names(data)){

      xgb_model = train(
        select(mydata(),"LotArea","YrSold"), as.vector(t(mydata()["SalePrice"])),
        trControl = xgb_trcontrol,
        tuneGrid = xgbGrid,
        method = "xgbTree"
      )

      predictor = Predictor$new(xgb_model, data = select(mydata(),"LotArea","YrSold"), y = mydata()["SalePrice"])
      shapley = Shapley$new(predictor, x.interest = select(mydata(),"LotArea","YrSold")[1,])
      shapley$plot()      
    }
  })


}

shinyApp(ui, server)

И образец входных данных:

https://drive.google.com/file/d/1R8GA0fW0pOgG8Cpykc8mAThvKOCRCVl0/view?usp=sharing

1 Ответ

0 голосов
/ 03 января 2019

и это сработало. Здесь приложение на моем аккаунте shinyapp.io. Потребовалось время, чтобы загрузить и запустить.

Возможно, вам придется проверить версию приложения. Вот версии пакетов, которые у меня есть. Я на R версии 3.5.2 (2018-12-20) и RStudio 1.1.463.

shiny app upload

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...