问题描述
在我的Shiny应用程序中,用户可以上传一个文件,该文件存储为reactive
数据帧。在下面显示的反应表达式中,我调用了一个外部耗时函数(称为performDigestion),该函数需要几秒钟才能完成。
fastafile_data <- reactive(){
inFile_fastafile <- input$fastaFile
req(inFile_fastafile)
ext <- tools::file_ext(inFile_fastafile$datapath)
validate(need(ext == "fasta","Please upload a fasta file"))
dt.seq <- readAAStringSet(inFile_fastafile$datapath)
tbl <- performDigestion(dt.seq) ##the time-consuming step
return(tbl)
}
接下来,我呈现一个数据表以在UI中呈现 fastafile_data 的结果:
output$dt_fastafile <- DT::renderDataTable({
withProgress(message = 'computation in progress,this step might take a while. Please wait...',{
incProgress(1/1)
fastafile_data()
})
},options = list(scrollX = TRUE,dom = 'lfrtip',pageLength = 10,lengthMenu = c(10,25,50,100)),rownames = FALSE)
在UI中,我还有两个附加组件(sliderInput
和numericInput
),在服务器端,我通过两个observeEvent
处理它们的值。
我想实现的是每次触发这两个附加组件中的任何一个时,更新 fastafile_data 数据帧,而无需再次读取input $ fastaFile并重新运行耗时的performDigestion()函数。理想情况下,我希望仅在用户上传新文件时再次触发上述响应过程。
我认为这里的问题出在我的逻辑上和/或存在我目前所缺少的在ShinyR中执行此操作的更聪明的方法?你能给我指出正确的方向吗?
编辑:
当我尝试通过第二个响应式fastafile_data
处理响应式fastafile_data_new
时,将重新执行第一个fastafile_data
。
fastafile_data_new <- reactive({
dt <- fastafile_data()
##### the condition I'd like to apply
dt$identifiable <- ifelse(dt$length >= min_peptide_length$choice & dt$length <= max_peptide_length$choice & dt$`mass [Da]` < max_peptide_mass$choice,1,0)
return(dt)
})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)