Programmatic tagging and giving error is tag not found on RStudio Connect

Hello,

I have created an app in shiny that allows users users to upload flash reports to RStudio Connect. I now want to create an if else statement to produce a modalDialog (showModal()) that gives a message that say "report successfully uploaded" if the report was uploaded or to stop the app from executing the upload and give an error message if the report did not upload.

here is what my code looks like, it works when the report is successfully uploaded and the message is displayed but if an error occurs and the report cannot get uploaded the app just crashes and the message is not displayed. this is my server.R file:

function(input, output){
  
  observeEvent(input$upload, {
    
    require(input$file)
    
    file <- file.copy(from = input$file$datapath, 
                      to = paste0(tempdir(),input$pubname,
                                  " - ",
                                  input$pubmonth,
                                  " ",
                                  input$pubyear,
                                  ".pdf"))
    
    
    if(!is.null(input$file)){
      
      #readRenviron("~/rstudio/connectapi/.Renviron.alt")
      
      client <- connect(host = "http://srv",
                        api_key = "key"
      )
      
      
      bnd <- bundle_static(path = input$file$datapath)
      
      content_1 <- deploy(client,bnd,name = connectapi ::: create_random_name(length = 50),title = paste0(input$pubname, " - ", input$pubmonth, " ", input$pubyear), access_type = "logged_in")
      
      all_users <- get_users(client,page_size = 20,prefix = NULL,limit = 200)
      
      one_user <- all_users %>% filter(username == toupper(input$username))
      
      one_user_guid <- one_user %>% pull(guid)
      
      content_1 %>%
        
        acl_add_collaborator(
          one_user_guid
        )
      
      
      myapp <- set_content_tag_tree(content_1,"Reports",input$unitname, input$pubname, input$pubyear, input$pubmonth)
      
      #myapp <- deploy(client, bnd, name = tempdir(),input$pubname," - ",input$pubdate,title = paste0(input$pubname, " - ", input$pubdate))
      
      content_1$update(owner_guid  = one_user_guid)
      
        
        if(input$upload == TRUE) {
          
          showModal(modalDialog("Report Uploaded"))
          
        } else {
          
          stop()
          
          showModal(modalDialog("Error in uploading report"))
        
        
      }
      

      poll_task(myapp)
      
      browse_dashboard(myapp)
      
      
      
      
    }
    
  }
  
  )
  
}


In the app the only way to get an error is if the content_tag_tree is not correctly specified. So if the tag is not correctly specified how can I stop the deployment and show an error.

Thanks

Hi,

stop() executes an error action which will cause your app to crash (unless it is handled), so if you want users to be able to carry on using the app if the upload isn't successful then you shouldn't use that here.

If you want poll_task and browse_dashboard to only be run if input$upload == TRUE, then move them inside the if statement:

      if(input$upload == TRUE) {
        
        showModal(modalDialog("Report Uploaded"))
        
        
        
        poll_task(myapp)
        
        browse_dashboard(myapp)
        
      } else {
        
        showModal(modalDialog("Error in uploading report"))
        
        
      }

Hope that helps.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.