Can shiny text input drive https get request

Hi
Im trying to pass the text input string to a https get request. Basically trying to allow the user to input text , hit the api, and return data for that user. Is the achievable?

Yep can confirm this is achievable through personal experience. If you have sample code we can work through together.

I think my issue is Im trying to use the api but I have no default Id.
So when I knit, the api gets hit with a blank.

textInput(inputId = 'Id', label = 'Id', value = "")
actionButton('submit', 'Submit', icon = icon('refresh'))

v<-reactiveValues()
v<-str_to_upper(v)

url<-GET(paste0("https:/abcdefghijklmnop/",
v,
"rest_of_api")
data<-fromJSON(rawtoChar(url$content))

Your help is greatly appreciated
Thanks in advance
Vincent

You can start with a valid default value in your textInput, or use the req function to handle missing values inside your presumed observeEvent that houses your GET request. Something like: req(input$Id). You can follow this doc: https://shiny.rstudio.com/articles/req.html

Also it doesn’t look like you are passing input$Id to your reactiveValue container in the code you sent, but I understand you did not send the entire code

1 Like

hi Michael.

I managed to use glue to paste text from textinput into a URL.
I also use the selected argument in the ui textInputs which allows me to set a default so when my app loads it sends a query straight away to populate a table.

Very cool.

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.