以下代码生成一个 GUI,用户可以在其中输入文件路径。代码预处理这些文件路径并保护结果。这个想法是将这些输入传递给 Rmarkdown 的渲染函数,并在第一次按下操作按钮时将这些值发送到渲染函数,以便渲染另一个使用这些值的 Rmarkdown 文件。这就是它在理论上的工作原理,实际上第一次按下按钮会导致渲染发生,但实际上没有任何参数是与第一次按下按钮一起发送的。但是,按下第二个按钮,一切正常。谁能看到我的代码中的缺陷,即阻止第一个按钮按我想要的方式运行?
我试着环顾四周,看看其他人是否已经弄清楚了,老实说,我认为我发现的只是也许我使用了隔离()?抱歉,我对 R 闪亮很陌生。
GUIforRmarkdowngeneration
标题:“为数据生成 Rmarkdown 报告”运行时:闪亮
输出:html_notebook
#setwd("/home/alan/Desktop/wts/filestosaveandcarryover/tiamatfiles")
knitr::opts_chunk$set(echo=TRUE)
library(reticulate) # <- only needed to run python
#use_python("/Users/dyarmosh/anaconda3/bin/python")
library(shinyFiles)
library(glue)
library(stringr)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
shinyFilesButton("Btn_GetFile", "Choose forward fastq" ,
title = "Please select a file:", multiple = FALSE,
buttonType = "default"),
br(),
selectInput("Selected_Panel", "Select Panel", choices = c("bacillus","burkholderia","yersinia")),
br(),
# #submitButton("Begin Analysis") - fix this no select item from file system
actionButton("Start", "Begin Analysis")
),
mainPanel(
br(),
textOutput("fwdftext"),
br(),
textOutput("revftext"),
br(),br(),
textOutput("paneltext"),
br(),br(),
textOutput("completion")
))
)
rvs <- reactiveValues() #renamed to rvs
server <- function(input,output,session){
volumes = getVolumes()
observe({
shinyFileChoose(input, "Btn_GetFile", roots = volumes, session = session)
req(input$Btn_GetFile)
req(input$Selected_Panel)
req(input$Start)
fwd_selected <- parseFilePaths(volumes, input$Btn_GetFile)
rvs$fwdfastq <- as.character(fwd_selected$datapath)
if (str_detect(rvs$fwdfastq,"R1")){rvs$revfastq <- str_replace(rvs$fwdfastq,"R1","R2")}
if (str_detect(rvs$fwdfastq,"R2")){rvs$revfastq <- str_replace(rvs$fwdfastq,"R2","R1")}
class_selected <- parseFilePaths(volumes, input$ClassifierFile)
kmer_selected <- parseFilePaths(volumes, input$StoredKmerFile)
rvs$panopt <- as.character(input$Selected_Panel)
rvs$start <- input$Start
output$fwdftext <- renderText({paste("Entered Forward File:", rvs$fwdfastq)})
output$revftext <- renderText({paste("Matched Reverse File:", rvs$revfastq)})
output$paneltext <- renderText({paste("Entered Panel:", rvs$panopt)})
})
observeEvent(input$Start, {
print(paste(rvs$panopt,rvs$fwdfastq,rvs$revfastq, rvs$class,rvs$kmer))
rmarkdown::render("testinput.Rmd",
params = list(
panelname = rvs$panopt,
r1filename = rvs$fwdfastq,
r2filename = rvs$revfastq,
classifier = rvs$class,
kmer = rvs$kmer
),
output_file = paste0("AmpSeqClass_Report_",strsplit(basename(toString(rvs$fwdfastq)),"[.]")[[1]][1],"_",str_replace(c(Sys.time())," ","_"),".html"))
output$completion <- renderText({paste("Rmarkdown Document render is complete at ",toString(Sys.time()))})
})
}
observe({
req(rvs$fwdfastq)
req(rvs$revfastq)
req(rvs$panopt)
req(rvs$start)
})
shinyApp(ui = ui, server = server)
testinputfile.Rmd
标题:执行内容输出:html_document:参数:r1filename:标签:“转发:”值:BurkP-130611_S12_100_L001_R1_001.fastq r2filename:标签:“反向:”值:BurkP-130611_S12_100_L001_R2_001.fastq 面板名称:标签:“AP:”值:芽孢杆菌输入:选择选项:[芽孢杆菌、伯克霍尔德氏菌、耶尔森氏菌]
setwd("/home/alan/Desktop/wts/filestosaveandcarryover/tiamatfiles")
knitr::opts_chunk$set(echo=TRUE)
library(reticulate) # <- only needed to run python
#use_python("/Users/dyarmosh/anaconda3/bin/python")
print(params)
基本上,如果您可以在第一次单击操作按钮时正确生成 rmarkdown,并且传递的参数都不是 NULL,那就是解决方案