我想从我的服务器端(指向服务器端的链接)或本地机器上传文件,然后将处理数据集以进行一些可视化。有什么方法可以从我的简单代码中更新以从我的服务器端或本地机器上传文件。目前我的代码只能从本地机器上传,看起来像这样:
用户界面
fluidPage(
titlePanel("Data Browser"),
sidebarLayout(
box(width = 12,
br(),
# radioButtons("filetype", "Select file type",choices=c("csv file","xlsx file", "xls file")),
fileInput("file","Choose file to upload..",accept = c("text/csv","text/comma-separated-values,text/plain",".csv",".xlsx",".xls"))
),
mainPanel(
width = 12,
uiOutput("data_browsing")
)
)
)
服务器.R
############################################################
############## Datasets in and out #########################
############################################################
# loading data
data <- eventReactive(input$file, {
extension <- tools::file_ext(input$file$name)
filepath <- input$file$datapath
switch(extension,
csv = read.csv(filepath),
xls = readxl::read_xls(filepath),
xlsx = readxl::read_xlsx(filepath)
)
})
#get data from data browser
data_input <- reactive({
data()
})
# info of the file
# output$about_file<-renderTable({
# summary(input$file) #input$file1
# })
output$about_file <- renderPrint({str(data())})
# to display data
output$display <- renderDataTable({
dataset = data()},
filter = 'top',escape = FALSE, options = list(pageLength = 10,
scrollX='500px',autoWidth = TRUE))
# passing to UI finally
output$data_browsing<-renderUI({
if(is.null(data())){
}else if(length(data())==1){
#h4(br(),br(),"Mismatch in formats of file selected and uploaded!",style = "font-style: italic;font-weight: bold;color: red;text-align: center;")
h4(br(),br(),"Mismatch in formats of file selected and uploaded!",style = "color:red")
}else{
tabsetPanel(tabPanel("Data Browse",dataTableOutput("display")),
tabPanel("Data Summary", verbatimTextOutput("about_file")))
}})
# End of Loading data
############################################################
################# End of datasets part ####################
############################################################