【发布时间】:2020-05-11 16:28:52
【问题描述】:
我有一个Shiny 应用程序,用户可以将.txt 文件上传到该应用程序,然后用户可以使用该应用程序创建绘图。该图取决于用户根据上传数据的列名选择输入。这些输入是下拉列表,一旦数据上传,列名就会出现在其中。
该应用自 2020 年 1 月 23 日起运行。但是今天(25/01/2020),在没有对代码进行任何更新的情况下,下拉输入不再显示上传的数据框列的名称。运行应用程序时没有出现下拉列表中缺少列名的错误。除了这个问题,该应用程序运行完美(但显然无法绘制)。
我已经从应用程序中删除了以下代码,以提供上传数据框和使用下拉列表的示例。该代码与它在应用程序中显示的完全一样,并且在本示例中有效。为了得到同样的问题(下拉列表中缺少列名),您需要从 GitHub 克隆应用程序,因为我还没有找到重现丢失列名的方法。
非常感谢任何帮助!
# example data to upload to the app
data <- data.frame(this = 1:10, is = 1:10, some = 1:10, great = 1:10, example = 1:10, data = 1:10)
write.table(data, "data_frame.txt",
row.names = FALSE, col.names = TRUE, quote = FALSE, sep = "\t")
library(shiny)
library(data.table)
ui <- fluidPage(
sidebarPanel(
helpText("Select paramaters for data upload then upload data. Functions based on R read.table()."),
checkboxInput(
inputId = 'header',
label = 'Header',
value = TRUE
),
checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),
radioButtons(
inputId = 'sep',
label = 'Separator',
choices = c(
Comma = ',',
Semicolon = ';',
Tab = '\t',
Space = ''
),
selected = '\t'
),
radioButtons(
inputId = "quote",
label = "Quote",
choices = c(
None = "",
"Double Quote" = '"',
"Single Quote" = "'"
),
selected = '"'
),
fileInput(
inputId = "file1",
label = "Track 1",
multiple = TRUE,
accept = c(
"text/csv",
"text/comma-separated-values",
"text/plain",
".csv"
)
),
selectInput("label_column",
"Label:",
choices="",
selected = "")
))
server <- shinyServer(function(input, output, session) {
# Read data from .csv/.txt files
track2_data1 <- eventReactive(input$file1, {
rbindlist(
lapply(
input$file1$datapath,
FUN = read.csv,
header = input$header,
sep = input$sep,
quote = input$quote
),
use.names = TRUE,
fill = TRUE
)
})
# drop down menu
observeEvent(input$file1, {
updateSelectInput(session,
"label_column",
choices = c("",colnames(track2_data1())))})
})
shinyApp(ui = ui, server = server)
sessInfo():
运行前shiny::runApp():
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.2 tools_3.6.2 packrat_0.5.0
运行后shiny::runApp():
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] markdown_1.1 rmarkdown_2.1 fs_1.3.1 stringr_1.4.0
[5] shinycssloaders_0.3 dplyr_0.8.3 circlize_0.4.8 data.table_1.12.8
[9] plotly_4.9.1 ggplot2_3.2.1 shinythemes_1.1.2 shinyLP_1.1.2
[13] shinydashboard_0.7.1 shiny_1.4.0
loaded via a namespace (and not attached):
[1] shape_1.4.4 tidyselect_0.2.5 xfun_0.12 purrr_0.3.3 colorspace_1.4-1
[6] vctrs_0.2.2 htmltools_0.4.0 viridisLite_0.3.0 yaml_2.2.0 rlang_0.4.3
[11] later_1.0.0 pillar_1.4.3 glue_1.3.1 withr_2.1.2 lifecycle_0.1.0
[16] munsell_0.5.0 gtable_0.3.0 htmlwidgets_1.5.1 GlobalOptions_0.1.1 evaluate_0.14
[21] knitr_1.27 fastmap_1.0.1 crosstalk_1.0.0 httpuv_1.5.2 Rcpp_1.0.3
[26] xtable_1.8-4 promises_1.1.0 scales_1.1.0 jsonlite_1.6 mime_0.8
[31] packrat_0.5.0 digest_0.6.23 stringi_1.4.5 grid_3.6.2 tools_3.6.2
[36] magrittr_1.5 lazyeval_0.2.2 tibble_2.1.3 crayon_1.3.4 tidyr_1.0.2
[41] pkgconfig_2.0.3 rsconnect_0.8.16 assertthat_0.2.1 httr_1.4.1 rstudioapi_0.10
[46] R6_2.4.1 compiler_3.6.2
【问题讨论】:
-
您介意分享您的
sessionInfo()吗?我从您的问题和 GH 存储库中运行了代码,它对我有用。 -
我已编辑问题以包含运行应用程序前后的会话信息
-
sessionInfo()之间的唯一区别是我们的操作系统。您问题中的应用程序运行良好;虽然,来自您的 GH 的错误不仅在“label_colum”中而且在一些列名中也有一些小错误(即:您的数据示例有一个“Pvalue”列,但是当它从 renderPlotly 调用时,应用程序正在调用该列“pvalue " 这会导致一个小错误)。如果这对您来说更容易,我可以分叉您的回购并推送其中一些更改。 -
@Antarqui ,我很清楚,当您从 GH 运行应用程序时,下拉列表会填充上传数据中的列名?唯一的区别似乎是操作系统?我已经在 Windows 10 和另外两台 Mac 上运行了该应用程序,但我仍然遇到同样的问题。不要担心其他错误,这些仍然需要更改才能处理所有上传的数据帧 - 但感谢您的提议!
标签: r shiny reactive shiny-reactivity