收到此消息-警告:as.tbl错误:发布我闪亮的应用程序时找不到函数“ as.tbl”

时间:2018-10-23 01:12:02

标签: r shiny dplyr

当我在本地运行闪亮的应用程序时,它运行正常,但是当我在日志中看到此代码时:

2018-10-23T00:54:15.496879+00:00 shinyapps[529396]: Loading required package: data.table
2018-10-23T00:54:21.417674+00:00 shinyapps[529396]: Warning: Error in as.tbl: could not find function "as.tbl"

这是代码

combined <-
  merge(loans, banks[, c("Year", "Agency", "ID", "Name")],
        by = c("Year", "Agency", "ID")) %>%
  mutate(Loan_Bucket = cut(Loan_Amount_000,       #appending a Loan_Bucket column to the dataframe
                           breaks = c(0, 50, 350, 2000, 5000, 15000, 40000, 100000),
                           labels = 1:7),
         right = FALSE
  ) %>% as.tbl                                    #tbl prevents printing the whole dataframe by mistake

我使用require(dplyr)加载了dplyr,但这仍然在发生。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在server.r中,您拥有

options(warn = -1)
packages = c("scales", "readr", "plotly", "editrules", "stringr", "jsonlite",
         "devtools", "tidyr", "data.table", "rjson", "scales", "dplyr", 
"gridExtra", "shiny", "ggplot2")
x = sapply(packages, function(x) if (!require(x, character.only = T)) 
install.packages(x))
rm(x, packages)

安装必需的软件包,但是在安装之后,这些软件包将不会加载。

尝试一下:

x = sapply(packages, function(x) {
         if (!require(x, character.only = T)) install.packages(x)
         require(x)
})

p.s:我建议在GitHub上共享您的仓库,这样其他人就不必下载就可以查看代码。