0

The following code produces a GUI where an user can input files paths. The code pre-processes those file paths and safes the results. The idea is that those inputs are passed to a render function for Rmarkdown and, on the first action button press, sends those values to the render function such that another Rmarkdown file is rendered that uses those values. That is how it works in theory, in practice the first button press causes a render to happen, but non of the params are actually sent along with the first button press. However, the second button press on, everything works fine. Can anyone see the flaw in my code, that is preventing the first button press to behave the way I want it to?

I have tried looking around to see if someone else has figured this out and honestly all I think i figured out is maybe I use isolate()? sorry i am very new to R shiny.

GUIforRmarkdowngeneration


title: "Generate Rmarkdown Report for data" runtime: shiny

output: 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


title: Perform stuff output: html_document: params: r1filename: label: "Forward:" value: BurkP-130611_S12_100_L001_R1_001.fastq r2filename: label: "Reverse:" value: BurkP-130611_S12_100_L001_R2_001.fastq panelname: label: "AP:" value: bacillus input: select choices: [bacillus,burkholderia,yersinia]


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)

basically if you can get the rmarkdown to generate properly on the first action button click, with non of the passed params being NULL, that is the solution

  • 2
    Would you be able to simplify this question somewhat? That's a lot of code to "just" test a button-press triggering `render`, I believe you'd be able to generate a trivial example in under 40-50 lines that demonstrates the phenomenon. (Lots of code and be daunting. I won't spend time here trying to parse meaningful code from unrelated, while guessing or faking your data that we don't have.) – r2evans Jul 15 '19 at 20:49
  • 1
    ok I will try to prune it down more – Alan Shteyman Jul 15 '19 at 20:55
  • things I dont know how much of the complexity of my R shiny app might be affecting the results so I have trimmed it down as much as I can while maintaining different types of inputs, etc. – Alan Shteyman Jul 15 '19 at 21:12
  • Do you know how I can modfiy code on the question I asked? when I click edit it is only letting me change my summary and nothing else. – Alan Shteyman Jul 15 '19 at 21:14
  • You should always be able to [edit](https://stackoverflow.com/posts/57046948/edit) your own questions, that is not a reputation-based privilege/milestone. – r2evans Jul 15 '19 at 22:14
  • change made. I apologize about the confusion. – Alan Shteyman Jul 15 '19 at 22:32

0 Answers0