【问题标题】:Shiny reactive check if file is choose闪亮的反应检查是否选择了文件
【发布时间】:2018-06-22 02:25:12
【问题描述】:

早上好。我想检查 fileInput 中是否选择了文件,所以我必须创建反应函数,但这不起作用。

ui.R

        fileInput("file_input","Choose your file in csv")             

        mainPanel("main panel",textOutput("choose"))

服务器.R

library(shiny)
isFileChoose<-function(){reactive({

  if(is.null(input$file_input))

    return (FALSE)

  else

    return (TRUE)


  })  }


server <- function(input, output) {


 if(isFileChoose()==FALSE)
{
 output$choose<-renderText("Not selected file")

}

 }

【问题讨论】:

    标签: r shiny reactive


    【解决方案1】:

    我认为你不能只在这样的函数中使用响应式,请参阅here。你可以这样做:

    library(shiny)
    
    ui <- fluidPage(
      fileInput("file_input","Choose your file in csv"),            
      textOutput("choose")
    )
    
    server <- function(input, output) {
    
      output$choose <- reactive({
        if(is.null(input$file_input))
        {
          "No input given yet."
        }
        else
        {
          "Now we can process the data!"
        }
      })
    
    }
    
    shinyApp(ui = ui, server = server)
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2011-05-09
      • 2020-08-01
      • 2016-01-06
      • 2020-07-04
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      相关资源
      最近更新 更多