0

重现我的数据集的步骤。

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: 

在 Shiny 中修复此问题的解决方案。在引入 unnest() 之前,我必须先从数据框中取出 NULL 值。

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

0 回答 0