r shiny:make fileInput小部件在文件输入后消失

时间:2014-09-18 07:01:10

标签: r widget shiny

我可以让文件输入后fileInput小部件消失吗?或者我可以摆脱蓝色进度条吗?

谢谢!

1 个答案:

答案 0 :(得分:3)

HelloStéphaneLaurent回答了一个类似的问题in this post,给出了一个最小的例子:

data("kyphosis", package = "rpart")
write.table(kyphosis, file = "kyphosis.txt", row.names = FALSE)


library(shiny)
runApp(list(
  ui = pageWithSidebar(
    headerPanel = headerPanel(" "),
    sidebarPanel = sidebarPanel( conditionalPanel(condition = "output.fileUploaded",
                                                  fileInput(inputId = "file_input", label = "Input" ) )),
    mainPanel = mainPanel( tableOutput(outputId = "table"))
  ),
  server = function(input, output) {

  getData <- reactive({
    if(is.null(input$file_input)) {
      return(NULL)
    } else {
      return(read.table(input$file_input$datapath, header = TRUE))
    }
  })

  output$fileUploaded <- reactive({
    return(is.null(getData()))
  })

  output$table <- renderTable({
    head(getData())
  })
  outputOptions(output, 'fileUploaded', suspendWhenHidden=FALSE)
  }
))