r - 闪亮:上传数据后updateSelectInput为空
问题描述
我有一个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
解决方案
我已经设法通过withSpinner()
从ui.R
. 这位于第 261-263 行:
mainPanel(
withSpinner(uiOutput("pdf"))
))))),
修复:
mainPanel((uiOutput("pdf")))
)))),
我不太清楚为什么这解决了这个问题......
推荐阅读
- reporting-services - 为什么未选择所有参数时 SSRS 公式会引发错误?
- java - Spring Websocket ChannelInterceptor 未触发 CONNECT 事件
- python - 如何在子类中覆盖基类的静态抽象方法?
- python - 如何在 Flask 的 if 条件下调用 render_template?
- css - Vue cli 在 css 中构建生产更改不透明度
- pandas - All() 正在打印每次 else 语句
- javascript - 为什么在我单击右侧“箭头”后我的页面不再显示我的“.wall”(.wall 是额外信息)[netflix 滑块]
- javascript - React 的 Text-Mask 库可以与 Redux 一起使用吗?
- java - 使用流将 Java 列表转换为映射,其中映射中的每个值共享相同的属性
- path - 如何让我的寻路算法突出显示最短路径?