使用 R 的 Shiny 中的 UpdateCheckboxGroupInput 会产生 vroom 错误

问题描述 投票:0回答:1

我正在尝试上传 csv 文件,然后

updatecheckboxGroupInput
使用文件中的一列。当我没有 ui
checkboxGroupInput
observeEvent
/
updateCheckboxGroupInput
时,它工作得很好。但是当我添加它们时,我收到以下错误:

Warning: Error in vroom::vroom: `file` is not one of the supported inputs:
• A filepath or character vector of filepaths
• A connection or list of connections
• Literal or raw input
122: \<Anonymous\>
121: signalCondition
120: signal_abort
119: rlang::abort
118: cli::cli_abort
117: standardise_path
116: vroom::vroom
115: read_csv

我不明白为什么当我不使用 vroom 时它会出现在其中,也不明白它与更新输入有什么关系。

library(shiny)
library(readr)
holiday_movie_genres <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-12-12/holiday_movie_genres.csv")

write.csv(holiday_movie_genres, "hmg.csv")
ui <- fluidPage(
  checkboxGroupInput("genre", "Select Genre", choices = NULL),
  fileInput("movie_file", "Upload File"),
  tableOutput("movie_table")
)

server <- function(input, output, session) {
  movie_reactive <- reactive({
    read_csv(input$movie_file$datapath)
  })

  output$movie_table <- renderTable({
    movie_reactive()
  })

  observeEvent(movie_reactive(), {
    updateCheckboxGroupInput(inputId = "genre", choices = unique(movie_reactive()$genres))
  })
}

shinyApp(ui, server)

创建于 2024-03-16,使用 reprex v2.1.0

r shiny
1个回答
0
投票

问题不是你想的那样。它在这里:

  movie_reactive <- reactive({
    read_csv(input$movie_file$datapath)
  })

确实,当应用程序启动时,

input$movie_file$datapath
NULL
,这就是问题所在。

做:

  movie_reactive <- reactive({
    req(input$movie_file)
    read_csv(input$movie_file$datapath)
  })
© www.soinside.com 2019 - 2024. All rights reserved.