很难为此提供一个代表,因为该问题仅在我使用我的应用程序的部署版本时发生,但我希望我可以提供足够的详细信息,以便有人能够帮助我了解导致问题的原因。我正在使用 pivot_longer 在 Shiny 中按下按钮来旋转表格。我的表格有点复杂,因为表格中的某些“单元格”必须包含一个列表,不确定这是否是问题的一部分:
display_table <- tribble(~Project, ~Sample_Type, ~Date, ~Parameters, ~Units, ~A1, ~A7,
"PL", "A", "14-May-2020", "ARRIVE TIME", "", "10:00 am", "11:15 am",
"PL", "A", "14-May-2020", "DEPART TIME", "", "10:20 am", "11:37 am",
"PL", "A", "14-May-2020", "CREW", "", c("Joe", "Moe"), c("Jane", "Jack"))
final_table <<- display_table %>%
pivot_longer(
.,
cols = -c("Project", "Sample_Type", "Date", "Parameters", "Units"),
names_to = "Station",
values_to = "Values"
)
当我从 RStudio 运行应用程序时,这个支点工作得很好,我得到了预期的结果:
Project Sample_Type Date Parameters Units Station Values
1 PL A 14-May-2020 ARRIVE TIME A1 10:00 am
2 PL A 14-May-2020 ARRIVE TIME A7 11:15 am
3 PL A 14-May-2020 DEPART TIME A1 10:20 am
4 PL A 14-May-2020 DEPART TIME A7 11:37 am
5 PL A 14-May-2020 CREW A1 c("Joe", "Moe")
6 PL A 14-May-2020 CREW A7 c("Jane", "Jack")
但是,在部署时(使用 DesktopDeployR 或 RInno),按下按钮时屏幕变为灰色并且应用程序挂起。这是在错误日志中:
Warning: Error in : Can't specify a prototype with non-vctrs types.
vctrs methods must be implemented for class `AsIs`.
See <https://vctrs.r-lib.org/articles/s3-vector.html>.
91: vec_c
90: pivot_longer_spec
89: pivot_longer
88: function_list[[k]]
86: freduce
85: _fseq
84: eval
83: eval
81: %>%
80: observeEventHandler [C:\Users\smith\OneDrive\Documents\R\work_stuff\DesktopDeployR\app\shiny\/server.R#1353]
9: shiny::runApp
application terminated normally
有趣的是,gather() 工作得很好,但如果我能解决这个问题,我宁愿使用 pivot:
final_table <<- display_table %>%
gather("Station", "Values", -c("Project", "Sample_Type", "Date", "Parameters", "Units")) %>%
select("Project", "Sample_Type", "Date", "Station", "Parameters", "Values", "Units")