[英]Displaying Input file by user in R shiny
我可以使用fileInput選項創建一個接受用戶輸入的結構。 我想查看與輸出相同的文件。
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)
在應用程序的服務器部分中,將輸出更改為:
output$XX<-renderDataTable(input$ABC)
通過這種方式,函數知道它應該使用哪個輸入。
具有actionButton
和observeEvent
控件的解決方案。
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.