0

I have created a shiny app that takes user input and renders a pdf report. On my Windows laptop, it seems to run fine, but deploying it to shinyapps.io shows %PDF-1.5 %. how it runs locally

Here's the app.R:

library(shiny)
ui <- fluidPage(
  
  # App title ----
  titlePanel(h2("Datasheet", style="color:darkorchid")),
  helpText("Please enter the following information and download report"),
  fluidRow(
    
    column(6, 
           textInput("plasmid_ID", h4("Plasmid ID"),
                     value = ""),
           helpText("This will allow for easy identification"),
           textInput("person_name", h4("Name of the person filling the form:"),
                     value = ""),
           textInput("vector_name", h4("Name of the vector:")),
           downloadButton("report", "Generate report")
    ))
  
)

# Define server logic
server <- function(input, output) {
  output$report <- downloadHandler(
    # For PDF output, change this to "report.pdf"
    filename = "report.pdf",
    content = function(file) {
      # Copy the report file to a temporary directory before processing it, in
      # case we don't have write permissions to the current working dir (which
      # can happen when deployed).
      tempReport <- file.path(tempdir(), "report.Rmd")
      file.copy("report.Rmd", tempReport, overwrite = TRUE)
      # Set up parameters to pass to Rmd document
      params <- list(plasmid_ID = input$plasmid_ID,
                     person_name = input$person_name, 
                     vector_name = input$vector_name)
      
      # Knit the document, passing in the `params` list, and eval it in a
      # child of the global environment (this isolates the code in the document
      # from the code in this app).
      rmarkdown::render(tempReport, output_file = file,
                        params = params,
                        envir = new.env(),
                        intermediates_dir = tempdir())
    }
    )
      
  
}

shinyApp(ui = ui, server = server)

And the report.Rmd file is just a series of cat functions.

I am new to deploying shiny apps and have zero deployment/development knowledge in general. What functions would allow me to deploy and use the apps from the web server?

Deployment doesn't show any errors or problematic logs! enter image description here

7
  • Are you sure that works locally as it is? There is no downloadButton('report', 'Download report') in the UI to start the downloadHandler Commented Oct 11, 2023 at 8:14
  • Yes, just updated the question with actually running shinyApp UI, I feel the error has something to do with the fact that both app.R and report.Rmd are in the same directory and are bundled that way. Commented Oct 11, 2023 at 9:00
  • @Janki: Maybe it's not specific with shinyapps.io. Have you tried with different browsers and or Operating System ? For my local shiny-server (without shinyapps.io), my users can in general see the pdfs but some Windows users cannot and every MacOS users cannot also. Therefore I've installed https://github.com/mozilla/pdf.js in www\plugins\mozilla.pdf.js loaded in ui.R by <script src='plugins/mozilla.pdf.js/build/pdf.js'></script> and <script src='plugins/mozilla.pdf.js/build/pdf.worker.js'></script>. Commented Oct 11, 2023 at 12:11
  • @phili_b I can run it on Chrome with no issues, just went through the logs of shinyapps.io deployment, it looks like its starts rendering the pdf before input is added, which is maybe leading me to not even see my shiny app UI after deployment.. Commented Oct 11, 2023 at 12:45
  • 1
    thank you so much for the help @phili_b I figured the issue was with prerendering of rmarkdown, so just copied Hadley's code from his book Mastering Shiny and added my UI and server variables and now it works! I think it something to do with render function.. now onto figuring out the difference in my code that caused this! Commented Oct 12, 2023 at 20:45

1 Answer 1

0

I figured the issue was with prerendering of rmarkdown, so just copied Hadley's code from his book Mastering Shiny and added my UI and server variables and now it works! I think it something to do with render function.. nw onto figuring out the difference in my code that caused this!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.