作者acecc (cc)
看板R_Language
标题[问题] Shiny 套件请益
时间Thu Apr 18 22:05:45 2013
[问题类型]:
程式谘询(我想用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