R_Language 板


LINE

嗨,不好意思,一忙就忘记回应这篇文章了 我依照程式码修改成可自动上传一半的结果上去dropbox云端的版本 我当初撰写程式码时也参考过以下两个网址,给大家参考 https://daattali.com/shiny/persistent-data-storage/ https://shiny.rstudio.com/articles/persistent-data-storage.html 希望可以帮助到也拥有这个问题的版友们 ---以下程式码 library(shiny) library(shinyjs) library(DT) library(rdrop2) #example data #write.csv(data.frame(x=c(1:5)+rnorm(5),y=c(5:1)+rnorm(5)),"thedata.csv",row.names = F,fileEncoding = 'UTF-8') ui <- fluidPage( useShinyjs(), # 载入读取按钮 actionButton("btn", "Continue?"), # 使用者汇入资料 fileInput("userData", label="Your Data", multiple=T, accept=c(".csv")), # 第一个结果 DT::dataTableOutput("list1"), # 使用者输入值 numericInput("n", "wait n seconds", value=1), actionButton("btn2", "confirm?"), # 第二个结果 DT::dataTableOutput("list2"), plotOutput("plotResult") ) server <- shinyServer(function(input, output, session){ drop_auth(new_user = FALSE, key = "xxxxxxxxxxx", secret = "xxxxxxxxxxx", cache = TRUE) # 汇入使用者资料 getData <- reactive({ req(input$userData) out <- read.csv(input$userData$datapath) return(out) }) # 第一个复杂的计算 calResult1 <- reactive({ #抓取档案位置 file_name=drop_dir('yourapphere/data') if(dim(file_name)[1]<1){ #因为之前没资料,所以不显示继续按钮 hide("btn") d <- getData() #假装运算(第1次复杂运算) Sys.sleep(10) #上传第一次处理结果 write.csv(d,"thedata.csv",row.names = F,fileEncoding = 'UTF-8') drop_upload("thedata.csv",path = "yourapphere/data") #重新读取一次dropbox,抓取确切位置 file_name_path <<-drop_dir('yourapphere/data')$path_display }else{ #因为之前有资料,所以不显示上传按钮 hide("userData") #按按钮才读取 req(input$btn) #读取dropbox档案 file_name_path <<-file_name$path_display d <- drop_read_csv(file_name_path,fileEncoding = 'UTF-8',stringsAsFactors = F) } out <- d return(out) }) # 显示第一个结果 output$list1 <- DT:: renderDataTable( datatable(calResult1()) ) # 第二个复杂的计算 calResult2 <- reactive({ d <-calResult1() #假装运算(第2次复杂运算) req(input$btn2) Sys.sleep(isolate(input$n)) out <- d[order(d$x),] #记得,当结果出炉,记得删除第一次处理的结果 drop_delete(file_name_path) #关掉继续及选择时间按钮 hide("n");hide("btn2") return(out) }) # 显示第二个结果 output$list2 <- DT:: renderDataTable({ datatable(calResult2()) }) output$plotResult <- renderPlot({ d <- calResult2() plot(x=d$x, y=d$y) }) }) shinyApp(ui,server) --- ps:记得去套用成自己的dropbox api、档案位置也记得换 ※ 引述《puppy77 ( )》之铭言: : [问题类型]: : 程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来) : : [软体熟悉度]: : 入门(写过其他程式,只是对语法不熟悉) : [问题叙述]: : 我写了一个网页,主要功能是使用者汇入他的data : 网页会使用汇入的data做复杂的运算後显示出第一个结果 : 使用者检视过这个结果後再input一些值 : 网页再依第一个结果搭上这次的input的值做另一个复杂的运算 : 最後再显示出第二个结果及画图 : 因使用者看过第一个结果後会需要时间决定之後要input的值 可能是隔几天 : 又加上运算实在花很多时间 : (我已经很努力修改程式减少运算时间,但还是很久....Orz) : 所以希望能够在使用者下一次打开网页後能够恢复到他上次关掉的状态 : 有考虑过把所有的计算结果全部都汇出下次再汇入 : 但因为这样要汇出很多东西 又要再汇入很多东西(下面程式是简化过的) : 所以不知道是否能有其他更好的选择 : 又若真的必须把所有结果一一汇出的话 : 汇入的部分会建议从哪个步骤汇入?? : 譬如下面程式第一个计算结果 : 把汇入写在calResult1内或是output$list1内比较好?? : [程式范例]: : ui <- fluidPage( : # 使用者汇入资料 : fileInput("userData", label="Your Data", multiple=T, accept=c(".csv")), : # 第一个结果 : DT::dataTableOutput("list1"), : # 使用者输入值 : numericInput("n", "N", value=1), : # 第二个结果 : DT::dataTableOutput("list2"), : plotOutput("plotResult") : ) : server <- shinyServer(function(input, output, session){ : # 汇入使用者资料 : getData <- reactive({ : req(input$userData) : out <- read.csv(input$userData$datapath) : return(out) : }) : # 第一个复杂的计算 : calResult1 <- reactive({ : d <- getData() : out <- complicatedFunction1(d) : return(out) : }) : # 显示第一个结果 : output$list1 <- DT:: renderDataTable( : datatable(calResult1()) : ) : # 第二个复杂的计算 : calResult2 <- reactive({ : d <- calResult1() : out <- complicatedFunction2(d, input$n) : return(out) : }) : # 显示第二个结果 : output$list2 <- DT:: renderDataTable( : datatable(calResult2()) : ) : output$plotResult <- renderPlot({ : d <- calResult2() : plot(x=d$x, y=d$y) : }) : }) --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.40.155.25
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1521991458.A.5D6.html
1F:推 celestialgod: 感谢分享 03/25 23:27
2F:推 puppy77: 希望这能解决我的问题 感谢j大分享!!!! 03/27 23:31
3F:推 cywhale: 推一个~~ 04/08 23:03







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP