Unnest在Rstudio中运行良好,但在Shiny中抛出错误

时间:2018-03-15 18:05:09

标签: r shiny tidyr unnest

重现我的数据集的步骤。

library(tidyr) # Upgraded to --version 0.8.0.9000 with all fixes to unnest bugs. 

created_at <- c("2018-02-07T10:13:25Z", "2018-02-07T07:26:54Z", "2018-02-06T19:36:38Z", 
                 "2018-02-06T13:03:53Z")
labels <- list(structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
    structure(list(id = 656178303L, url = "https://api.github.com/repos", 
                   name = "Project: ETHIOPIA", color = "006b75", default = FALSE), .Names = c("id", 
                                                                                                    "url", "name", "color", "default"), class = "data.frame", row.names = 1L), 
    structure(list(id = c(829717165L, 133781065L), url = c("https://api.github.com/repos/", 
                                                           "https://api.github.com/repos/"
    ), name = c("Pre Deployment", "help wanted"), color = c("159818", 
                                                            "159818"), default = c(FALSE, TRUE)), .Names = c("id", "url", 
                                                                                                             "name", "color", "default"), class = "data.frame", row.names = 1:2), 
    structure(list(id = 461737195L, url = "https://api.github.com/repos/", 
                   name = "Project: KENYA", color = "006b75", default = FALSE), .Names = c("id", 
                                                                                           "url", "name", "color", "default"), class = "data.frame", row.names = 1L))

df <- data.frame(cbind(created_at,labels))

df %>%
    unnest(labels)

当我在Rstudio中运行时,这将运行良好,但当我在闪亮的应用程序中运行时。

"Error : Each column must either be a list of vectors or a list of data frames [labels].

我注意到在https://github.com/tidyverse/tidyr/issues/436上存在一个错误,但是为什么在Rstudio中运行它会运行良好并且在相同的环境中运行但是在Shiny应用程序中抛出该错误。

EDITED: 

固定在闪亮的解决方案。在引入unnest()之前,我必须首先从数据帧中取出NULL值。

df %>% 
  filter(!map_lgl(labels, ~all(is.na(.)))) %>% 
  mutate(labels = map(labels, bind_rows)) %>% 
  unnest() 

0 个答案:

没有答案