rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.38k stars 1.86k forks source link

Feature request: Allow inputs set in JS to be excluded from bookmarking (not from server side) #2309

Open daattali opened 5 years ago

daattali commented 5 years ago

When using URL bookmarking, any input that gets set in custom javascript using Shiny.onInputChange() gets added to the URL. That can be useful behaviour, but sometimes it's annoying - especially when there are any htmlwdigets on the page that sends big data to Shiny using inputs. In cases where we use an input more as an event signal rather than an actual input value is where this becomes not useful.

This causes the URL to be extremely long and in some cases long enough to be rendered useless because it can be 1000s of characters long.

This was originally reported as https://github.com/ropensci/plotly/issues/1447 but I later realized it happens with any htmlwidget.

It would be great to be able to somehow specify from Shiny.setInputValue that a specific value should not be bookmarked.

Example:

library(shiny)

ui <- function(req) {
  fluidPage(
    shinyjs::useShinyjs(),
    bookmarkButton()
  )
}

server <- function(input, output, session) {
  observe({
    shinyjs::runjs("Shiny.onInputChange('foo', 'bar')")
  })
}

shinyApp(ui, server, enableBookmarking = "url")

The bookmarkable URL is http://127.0.0.1:4155/?_inputs_&foo=%22bar%22.

Example with plotly (similar can be done with any htmlwidget):

library(shiny)
library(plotly)

ui <- function(req) {
  fluidPage(
    bookmarkButton(),
    plotlyOutput("plot")
  )
}

server <- function(input, output, session) {
  output$plot <- renderPlotly({
    plot_ly(economics, x = ~pop)
  })
}

shinyApp(ui, server, enableBookmarking = "url", options = list(port = 3900))

Resulting URL:

http://127.0.0.1:3900/?_inputs_&.clientValue-default-plotlyCrosstalkOpts=%7B%22on%22%3A%22plotly_click%22%2C%22persistent%22%3Afalse%2C%22dynamic%22%3Afalse%2C%22selectize%22%3Afalse%2C%22opacityDim%22%3A0.2%2C%22selected%22%3A%7B%22opacity%22%3A1%7D%2C%22debounce%22%3A0%2C%22color%22%3A%5B%5D%7D&.clientValue-plotly_relayout-A=%22%7B%5C%22width%5C%22%3A1570%2C%5C%22height%5C%22%3A400%7D%22
daattali commented 5 years ago

To clarify: I know I could exclude specific inputs in the server, but I would like to be able to exclude inputs directly from the javascript, so that the end user who builds a shiny app doesn't need to know about it

daattali commented 5 years ago

I believe this would be useful to remove a lot of the plotly inputs that get saved and are not useful

daattali commented 3 years ago

If it's too difficult to introduce a feature that allows inputs set from JavaScript to be excluded from bookmarking, perhaps a middle ground here can be to automatically exclude any input with a name that starts with __ or something similar.