EVOLUTION-MANAGER
Edit File: updateQueryString.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Update URL in browser's location bar</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for updateQueryString {shiny}"><tr><td>updateQueryString {shiny}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Update URL in browser's location bar</h2> <h3>Description</h3> <p>This function updates the client browser's query string in the location bar. It typically is called from an observer. Note that this will not work in Internet Explorer 9 and below. </p> <h3>Usage</h3> <pre> updateQueryString( queryString, mode = c("replace", "push"), session = getDefaultReactiveDomain() ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>queryString</code></td> <td> <p>The new query string to show in the location bar.</p> </td></tr> <tr valign="top"><td><code>mode</code></td> <td> <p>When the query string is updated, should the the current history entry be replaced (default), or should a new history entry be pushed onto the history stack? The former should only be used in a live bookmarking context. The latter is useful if you want to navigate between states using the browser's back and forward buttons. See Examples.</p> </td></tr> <tr valign="top"><td><code>session</code></td> <td> <p>A Shiny session object.</p> </td></tr> </table> <h3>Details</h3> <p>For <code>mode = "push"</code>, only three updates are currently allowed: </p> <ol> <li><p> the query string (format: <code>?param1=val1&param2=val2</code>) </p> </li> <li><p> the hash (format: <code style="white-space: pre;">#hash</code>) </p> </li> <li><p> both the query string and the hash (format: <code>?param1=val1&param2=val2#hash</code>) </p> </li></ol> <p>In other words, if <code>mode = "push"</code>, the <code>queryString</code> must start with either <code style="white-space: pre;">?</code> or with <code style="white-space: pre;">#</code>. </p> <p>A technical curiosity: under the hood, this function is calling the HTML5 history API (which is where the names for the <code>mode</code> argument come from). When <code>mode = "replace"</code>, the function called is <code>window.history.replaceState(null, null, queryString)</code>. When <code>mode = "push"</code>, the function called is <code>window.history.pushState(null, null, queryString)</code>. </p> <h3>See Also</h3> <p><code><a href="enableBookmarking.html">enableBookmarking()</a></code>, <code><a href="getQueryString.html">getQueryString()</a></code> </p> <h3>Examples</h3> <pre> ## Only run these examples in interactive sessions if (interactive()) { ## App 1: Doing "live" bookmarking ## Update the browser's location bar every time an input changes. ## This should not be used with enableBookmarking("server"), ## because that would create a new saved state on disk every time ## the user changes an input. enableBookmarking("url") shinyApp( ui = function(req) { fluidPage( textInput("txt", "Text"), checkboxInput("chk", "Checkbox") ) }, server = function(input, output, session) { observe({ # Trigger this observer every time an input changes reactiveValuesToList(input) session$doBookmark() }) onBookmarked(function(url) { updateQueryString(url) }) } ) ## App 2: Printing the value of the query string ## (Use the back and forward buttons to see how the browser ## keeps a record of each state) shinyApp( ui = fluidPage( textInput("txt", "Enter new query string"), helpText("Format: ?param1=val1&param2=val2"), actionButton("go", "Update"), hr(), verbatimTextOutput("query") ), server = function(input, output, session) { observeEvent(input$go, { updateQueryString(input$txt, mode = "push") }) output$query <- renderText({ query <- getQueryString() queryText <- paste(names(query), query, sep = "=", collapse=", ") paste("Your query string is:\n", queryText) }) } ) } </pre> <hr /><div style="text-align: center;">[Package <em>shiny</em> version 1.5.0 <a href="00Index.html">Index</a>]</div> </body></html>