简体   繁体   中英

Displaying Input file by user in R shiny

I am able to create a structure to accept input from the user by using fileInput option. I want to view the same file as output.

library(shiny)

ui<-fluidPage(


fileInput(inputId = "ABC", label="Input File", multiple = FALSE, accept = NULL,
        width = NULL, buttonLabel = "Browse...",
        placeholder = "No file selected"),



dataTableOutput('XX')

)


server<-function(input, output){

output$XX<-renderDataTable(ABC)
#output$XX<-renderDataTable(iris_2)  


}


shinyApp(ui, server)

In server part of the app, change the output to:

output$XX<-renderDataTable(input$ABC)

In this way, the function knows which input it should use.

A solution with actionButton and observeEvent control.

library(shiny)
library(DT)

ui <- fluidPage(
    fileInput(inputId = "ABC", label = "Input File", multiple = FALSE, accept = NULL,
                width = NULL, buttonLabel = "Browse...",
                placeholder = "No file selected"),

    actionButton(inputId = "submit", label = "Submit"),
    dataTableOutput("XX")
  )

server <- function(input, output) {
  observeEvent( input$submit, {
      data <- read.csv(input$ABC$datapath, header = TRUE, sep = ",")

      output$XX <- renderDataTable({
        datatable(data)
      })
    })
}
shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM