在Shinyapps.io上部署Shiny App时出错

时间:2019-12-14 13:08:29

标签: r shiny

尝试部署我的应用程序Shinyapps.io时遇到错误消息。

部署后出现此错误

This version of Shiny is designed to work with 'htmlwidgets' >= 1.5.
    Please upgrade via install.packages('htmlwidgets').

Attaching package: ‘DT’

The following objects are masked from ‘package:shiny’:

    dataTableOutput, renderDataTable


Attaching package: ‘data.table’

The following objects are masked from ‘package:dplyr’:

    between, first, last

The following object is masked from ‘package:purrr’:

    transpose

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Error in value[[3L]](cond) : ImportError: No module named pandas
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

这是我在app.R中编写的代码-当我在本地运行该应用时,该应用即可工作

library(shiny)
library(shinyWidgets)
library(tidyverse)
library(reticulate)
library(DT)
library(knitr)
library(data.table)
py_install("pandas")
boxing <- readRDS('boxingdatafull2.rds')
#reading model
p <- import("pandas")
cat_model <- py_load_object("catmodelsummary.pkl",pickle="pickle")
# cat_model <- p$read_pickle("catmodelsummary.pkl")
ui <- shinyUI(
  fluidPage(setBackgroundImage(src = "mayweather2.png"),
            headerPanel(fluidRow(
              column(offset = 5, width=5,
                     h2("Boxing Prediction App")),
              column(offset = 3, width = 7,
                     h5("Welcome to Emmanuel's boxing prediction app. Using this app you can get the probability of a fight ending in a given way. The model used to derive these predictions uses data extracted before the 23rd of November 2019. Any updates to the data will be shown here. Without further ado, let's get ready to rumble!"))
            )),
            fluidRow(column(offset = 5, width = 2,align="center",
                            titlePanel(h5(selectInput("dropdown","Select Boxer Weights",choices=unique(boxing$division)))))),
            fluidRow(column(offset = 3, width=3,
                            wellPanel(
                              fluidRow(
                                uiOutput("Names"),
                                uiOutput("boxerA")))),
                     column(width = 3, align="right",
                            wellPanel(style = "height:300px",
                                      fluidRow(
                                        uiOutput("Opponent"),
                                        uiOutput("opppic")
                                      )))),
            hr(),
            column(offset=5,width = 8,
                   actionButton("goButton","Start Predictions")),
            hr(),
            column(offset=3,width=6,
                   DTOutput("predictions"))
            # ,
            # hr(),
            # column(offset=5,width = 5, 
            #        uiOutput("boxergifs"))
  ) 
)

server <- function(input,output){
  output$Names <- renderUI({
    req(input$dropdown)
    df <- boxing %>% filter(division %in% input$dropdown)
    selectInput("names","Boxer A",choices = df$name)
  })
  output$boxerA <- renderUI({
    tags$img(src=paste(boxing[boxing$name == input$names, "global_id"],".jpg",sep=""),width=150)
  })
  output$Opponent <- renderUI({
    req(input$dropdown)
    df <- boxing %>% filter(division %in% input$dropdown)
    selectInput("names2","Opponent",choices = df$name)
  })
  output$opppic <- renderUI({
    tags$img(src=paste(boxing[boxing$name == input$names2, "global_id"],".jpg",sep=""),width=150)
  })

  observeEvent(input$goButton, {

    output$predictions <- renderDataTable({
      df1 <- boxing %>% filter(name %in% input$names)
      df2 <- boxing %>% filter(name %in% input$names2)
      df2$opp_loss <- df2$Loss.KO + df2$Loss.Other
      df2$opp_win <- df2$Win.KO + df2$Win.Other
      df1 <- df1 %>% select(Win.KO,Loss.Other,Loss.KO,Win.Other,KO.ratio,KnockedOut.ratio,Draw)
      df2 <- df2 %>% select(last6,KO.ratio,Win.Other,Win.KO,opp_loss,Loss.Other,opp_win,Loss.KO)
      setnames(df1,c("Win.KO","Loss.Other","Loss.KO","Win.Other","KO.ratio","KnockedOut.ratio"),c("winKO","lossOther","lossKO","winOther","KOratio","Knockedoutratio"))
      setnames(df2,c("last6","KO.ratio","Win.Other","Win.KO","Loss.Other","Loss.KO"), c("opp_last6","oppKOratio","opp_winOther","opp_winKO","opp_lossOther","opp_lossKO"))
      preds <- df1[,c("winKO","lossOther","lossKO","winOther","KOratio","Knockedoutratio","Draw")]
      preds2 <- df2[,c("opp_last6","oppKOratio","opp_winOther","opp_winKO","opp_loss","opp_lossOther","opp_win","opp_lossKO")]
      preds3 <- bind_cols(preds,preds2)
      df <- data.frame(probs = round(cat_model$predict_proba(preds3)*100,2))
      names(df)[1] <- "Draw"
      names(df)[2] <- "Loss"
      names(df)[3] <- "Win"
      #custom table
      datatable(df, container = htmltools::withTags(table(tableHeader(df))),options = list(pageLength=1,dom='tip'), rownames = FALSE, class = 'cell-border stripe')
    })

  })

}
shinyApp(ui = ui, server = server)

更新:

按照注释之一的建议升级htmlwidgets和python之后。部署我的应用后,我没有收到此错误消息

An error has occurred
The application failed to start (exited with code 1).
Error in value[[3L]](cond) : app.R did not return a shiny.appobj object.
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

0 个答案:

没有答案