Get url for content uploaded to RStudio Connect using get_vanity_url () function

Hello,

I am trying to get the URL of the content that I have uploaded to RStudio Connect using an app I created in shiny.

I want to use the get_vanity_url function to get the url for the the content that was just uploaded, I tried using the get_vanity_url function by I get an error, not sure if I am not using the function correctly?
Here is my code:

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 = "server",
                        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"))
          
          get_vanity_url(client, content_1)
          
        #  poll_task(myapp)
          
        #  browse_dashboard(myapp)
          
          
          
        } else {
          
          showModal(modalDialog("Error in uploading report"))
        
        
      }
      

     
      
      
    }
    
  }
  
  )
  
}


I then want the app to email this URL to the owner of this content, is this possible?

Would really appreciate some assistance

I managed to use the get_vanity_url() function. But, is there a way to get the full url of the content that is uploaded?

Glad to hear you got it to work! There have been some recent changes to the get_vanity_url() function (see NEWS), and some other helpers will likely be on their way.

In the meantime, there are a few ways to accomplish what I believe you are looking for. Do you mind articulating what you mean by "get the full url of the content"?

Also, please keep in mind that a reprex of the functionality that you are trying to understand is very helpful for other users to give you feedback! (I.e. unless there is a problem with the app itself, the rest of the app code is more confusing to us than helpful)

library(connectapi)

client <- connect()
#> Defining Connect with server: https://colorado.rstudio.com/rsc

myc <- content_item(client, "5cdcdedd-4276-451d-95f1-c4b591f9fb32")
get_vanity_url(myc)
#> [1] "/shinytest-example-app/"

myc$get_url()
#> [1] "https://colorado.rstudio.com/rsc/shinytest-example-app/"
myc$get_dashboard_url()
#> [1] "https://colorado.rstudio.com/rsc/connect/#/apps/5cdcdedd-4276-451d-95f1-c4b591f9fb32/"

Created on 2021-07-06 by the reprex package (v0.3.0)

Thanks @cole. I got what I was looking for from the get_url().

1 Like

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.