aoles / shinyURL

:link: Save and restore the state of Shiny app's widgets by encoding them in an URL query string
81 stars 21 forks source link

use history.replaceState instead of widget #6

Closed LukasGrebe closed 8 years ago

LukasGrebe commented 8 years ago

hi,

the broswers history.replaceState method updates the URL visible in the adressbar of the browser. I think it would be great to simply update the adressbar of the browser, instead of showing an extra UI element with the URL.

LukasGrebe commented 8 years ago

this clientside Code manipulates the query with every input change $(':input').change( (function(){ locationUriObj = URI(window.location); return function(event){ locationUriObj.setSearch(event.target.id,event.target.value); window.history.replaceState({},document.title,locationUriObj.toString()) } })());

it uses URI.js to manipulate the window.location URL's query

aoles commented 8 years ago

Hi Lukas, many thanks for pointing me to the history.replaceState() method! I've updated shinyURL to make use of it, now the changes are reflected in real time in the browser's addressbar. You can hide shinyURL widgets all together by setting display = FALSE in shinyURL.ui().

I've decided to leave the URL text field by default on, as it is useful in the context of displaying the shortened url. I might revisit this idea in future updates.