Fill a shiny form with request URL

75 views
Skip to first unread message

Daniel O'Quinn

unread,
May 26, 2015, 10:56:38 AM5/26/15
to shiny-...@googlegroups.com

I am attempting to pre-fill a form with a parameter appended to my request URL for a shiny page. The form I would like to fill is sourced as " <input id="name1" type="text" value="" class="shiny-bound-input"> " 

I have tried variations of a request URL as https://dajoq.shinyapps.io/Rapp4/?name1=emc with no success at having this form filled upon page load. Any ideas or thought from someone who as done this sort of thing before?

Dean Attali

unread,
May 26, 2015, 3:15:34 PM5/26/15
to shiny-...@googlegroups.com
As far as I know, shiny does not provide a mechanism to auto-fill inputs. At least I don't think it's meant to do that.

But you can do it yourself. When the server first loads, look at the URL and if any of the input values are provided, update those inputs. The one downside is you'd have to call a different `updateFooInput` for every input type so it might be a little tricky to generalize to many inputs without repeating your code.

runApp(shinyApp(
  ui = fluidPage(
    textInput("name", "Name"),
    numericInput("age", "Age", 25)
  ),
  server = function(input, output, session) {
    observe({
      query <- parseQueryString(session$clientData$url_search)
      if (!is.null(query[['name']])) {
        updateTextInput(session, "name", value = query[['name']])
      }
      if (!is.null(query[['age']])) {
        updateNumericInput(session, "age", value = query[['age']])
      }
    })
  }
))

If you add `?name=Hello&age=40` to the URL, those values will be set initially

Daniel O'Quinn

unread,
May 26, 2015, 3:26:49 PM5/26/15
to shiny-...@googlegroups.com
I will try this, do you know if there is a way to get the R source code?

Dean Attali

unread,
May 26, 2015, 3:28:16 PM5/26/15
to Daniel O'Quinn, shiny-...@googlegroups.com
I'm not sure what you mean -- the source code for what?  
On 26 May 2015 at 12:26, Daniel O'Quinn <daniel...@gmail.com> wrote:
I will try this, do you know if there is a way to get the R source code?

--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/g1p9HZmEpmo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/b435c13d-be39-40e2-8506-d5cb010ebe0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel O'Quinn

unread,
May 26, 2015, 3:59:18 PM5/26/15
to shiny-...@googlegroups.com
I lost the original files, server.r and ui.r, is there a way to retrieve?

Dean Attali

unread,
May 26, 2015, 4:01:54 PM5/26/15
to shiny-...@googlegroups.com
You mean from shinyapps.io?  Login to your account and go to the settings for that shiny app, somewhere there there's an option to download the source code
Reply all
Reply to author
Forward
0 new messages