Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: allow deleting an input that was removed using removeUI() #2374

Open
daattali opened this issue Apr 9, 2019 · 4 comments
Open

Request: allow deleting an input that was removed using removeUI() #2374

daattali opened this issue Apr 9, 2019 · 4 comments

Comments

@daattali
Copy link
Contributor

@daattali daattali commented Apr 9, 2019

Currently, when an input is removed using removeUI(), its UI is deleted from the DOM but the input still lives from the server's perspective. It would be great if it was possible to clear that input completely.

Personal opinion: I would want this to be the default behaviour, because an input that does not exist on the page should not exist in the server - it's a bit of a logical discrepancy - but that breaking change might cause a lot of trouble so perhaps adding a parameter to removeUI() to do this would be helpful.

@daattali daattali changed the title Request: allow deleting an input that as removed using removeUI() Request: allow deleting an input that was removed using removeUI() Apr 22, 2019
@daattali
Copy link
Contributor Author

@daattali daattali commented Apr 22, 2019

For anyone looking for a workaround until this gets implemented, my solution meanwhile it to set the value of any removed inputs to NULL using javascript, with Shiny.onInputChange("input", 'null')

Loading

@ColinFay
Copy link
Contributor

@ColinFay ColinFay commented Aug 29, 2019

Here's a reprex of this issue:

library(shiny)
ui <- fluidPage(
  actionButton("rmv", "Remove UI"),
  textInput("txt", "This is no longer useful", "plop")
)

# Server logic
server <- function(input, output, session) {
  observeEvent(input$rmv, {
    removeUI(
      selector = "#txt"
    )
  })
  observe({
    invalidateLater(1000)
    print(input$txt)
  })
}

shinyApp(ui, server)

I definitely second the idea of removing the value from the input list if the input is not there anymore.

The removeUI() function which can remove any part of the UI has to be kept, but there could be a removeInput() function, to be more specific to target the inputs.

Loading

@iqis
Copy link

@iqis iqis commented Jul 21, 2020

Just dropping a thought here. If you're managing the lifecycle of modules using objects from a bespoke class system, for example, R6, you can register your takedown code as the finalizer function of the module object. The finalizer function will run as the object is garbage collected.

Loading

@changwn
Copy link

@changwn changwn commented Aug 11, 2021

For anyone looking for a workaround until this gets implemented, my solution meanwhile it to set the value of any removed inputs to NULL using javascript, with Shiny.onInputChange("input", 'null')

Thank you so much for solution. Is this way to update all variable in 'input' as null ? Could I just update one variable as null? Thanks in advance.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants