精華區beta R_Language 關於我們 聯絡資訊
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: R的基本使用沒問題,但使用Shiny套件是完全的新手... 先寫個基本款來試試看... [問題敘述]: 程式做的事情很單純, 1. upload 一個檔案 2. 程式對每個Column做簡單的線性預測 3. 將結果download下來 程式我有丟上Glimmer Server http://glimmer.rstudio.com/glen/Pred/ 並附上一個簡易的測試檔案,可以用此檔案直接upload,並算出結果。 https://www.asuswebstorage.com/navigate/s/14B96034DC784748976F45174C9F274BY 但我有三個技術上的問題想克服,請教各位~ 1. 若同時間此程式有好幾個人同時使用,那麼很有可能會download到別人的output. 例如:A先跑完但還沒做download的動作,此時B也上傳了另一個檔案跑了另一個output出來 那麼這時候A 與 B去download檔案的時候,就都會download到B產生的output 請問我要怎麼能讓每個End user都能下載到自己產生的output? 這是server端的問題,還是我程式寫法的問題? 2. 請教一下有沒有辦法讓流程縮短為 a. upload 一個檔案 b. 程式對每個Column做簡單的線性預測且自動跳出結果問你要不要download 而不用讓End user再去點download? Shiny套件能做到這個效果嗎? 3. 有沒有辦法讓程式跑完自動將結果寄到指定的的E mail信箱而不用手動下載。 [程式範例]: 因為有兩段程式碼,我就直接貼在這兒了! #######ui.R library(shiny) shinyUI(pageWithSidebar( headerPanel("Hello!"), sidebarPanel( fileInput('file1', 'Input Data', accept=c('text/csv', 'text/comma-separated-values,text/plain')), tags$hr(), selectInput("dataset", "Download:", choices = "FIT"), downloadButton('downloadData', 'Download')), mainPanel( tableOutput("contents") ) )) #######server.R library(shiny) shinyServer(function(input, output) { output$contents <- renderTable({ inFile <- input$file1 if (is.null(inFile)) return(NULL) y <- read.csv(inFile$data, header= TRUE) data <- apply(y, 2, cumsum) fit <<- apply(data, 2, function(z){ z <- z[!is.na(z)] x <- 1:length(z) tempfit <- lm(z[-(1:6)] ~ x[-(1:6)]) coef(tempfit)[1] + coef(tempfit)[2] * 1:70 }) fit }) #browser() datasetInput <- reactive({ switch(input$dataset, "FIT" = fit) }) output$table <- renderTable({ datasetInput() }) output$downloadData <- downloadHandler( filename = function() { paste(input$dataset, '.csv', sep='') }, content = function(file) { write.csv(datasetInput(), file) } ) }) 有任何不清楚的地方麻煩再告訴我 感謝各位! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.16.37