Rerendering the same UI more times

Valter Beaković

I have this simple shiny app with two action buttons. The "Render" button renders a slider input control while the "Remove" button removes the same slider input. This works fine the first time but trying to rerender the same slider input the second time does not work. Any idea or explanation what may be wrong with the code?

This is the code:

    ui <- fluidPage(
            actionButton("render", "Render"),
            actionButton("remove", "Remove"),
            uiOutput("moreControls")
    )

    server <- function(input, output) {
            observeEvent(input$render, {
                    if (input$render > 0) {
                            output$moreControls <- renderUI({
                                    tagList(
                                            sliderInput("n", "N", 1, 1000, 500)
                                    )
                            })    
                    }
            })
            observeEvent(input$remove, {
                    if (input$remove > 0) {
                            removeUI(
                                    selector = "div[id='moreControls']"
                            )
                    }
            })

    }
    shinyApp(ui, server)
Eduardo Bergel

You can set the control to NULL to remove it. See code.

library(shiny)  

ui <- fluidPage(
  actionButton("render", "Render"),
  actionButton("remove", "Remove"),
  uiOutput("moreControls")
)

server <- function(input, output) { 

  rv <- reactiveValues() 

  observeEvent(input$render, { rv$action <- 'render' })
  observeEvent(input$remove, { rv$action <- 'remove' }) 

  output$moreControls <- renderUI({ 

    if (is.null(rv$action)) {return(NULL)} 

    if(rv$action == 'render'){ 
      sliderInput(inputId = "n",label =  "N", min = 1, max = 1000, value = 500)    
    } else {  
      return(NULL)
    } 
  }) 
}
shinyApp(ui, server)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Read in a sentence and print out only words that have the same letter repeated 3 or more times in a row

分類Dev

How to pseudo-randomize trials without repeating same condition more than three times

分類Dev

Loading the same image multiple times

分類Dev

Expand operator executing more times than expected

分類Dev

Filter more times in a Java 8 Stream

分類Dev

Angular ui - tabs controllers executed multiple times

分類Dev

mathjax + vue not rerendering equations

分類Dev

Getting same file downloaded multiple times concurrently

分類Dev

Performance of listening to the same firebase ref multiple times

分類Dev

Duplicate/Copy same file N times

分類Dev

sscanf - using same variable multiple times

分類Dev

Presenting same RatingScale multiple times in for loop

分類Dev

is it possible for JWT to generate a same token, two times?

分類Dev

How to use same foreign key multiple times

分類Dev

Recycling views shows same item multiple times

分類Dev

How to show the same ImageView multiple times programmatically?

分類Dev

Repeat same JS function multiple times on same page

分類Dev

Users who are logged in more than 2 times - bash script

分類Dev

Regex for digits not repeating more than five times in string such as contact number

分類Dev

Get items from Ruby Array that occur 2 or more times

分類Dev

sed a pattern followed with any single character one or more times

分類Dev

Extracting lines appeared consecutively for 3 times or more in Linux

分類Dev

Recall same UI View controller

分類Dev

Constructor with more than one instance of same type

分類Dev

Have two or more tuples with the same attribute value

分類Dev

How to assign more ranges to same variable?

分類Dev

JQuery: attach the same callback to one or more elements

分類Dev

VBA - Use same variables in more modules

分類Dev

React SVG not rerendering on attribute update

Related 関連記事

  1. 1

    Read in a sentence and print out only words that have the same letter repeated 3 or more times in a row

  2. 2

    How to pseudo-randomize trials without repeating same condition more than three times

  3. 3

    Loading the same image multiple times

  4. 4

    Expand operator executing more times than expected

  5. 5

    Filter more times in a Java 8 Stream

  6. 6

    Angular ui - tabs controllers executed multiple times

  7. 7

    mathjax + vue not rerendering equations

  8. 8

    Getting same file downloaded multiple times concurrently

  9. 9

    Performance of listening to the same firebase ref multiple times

  10. 10

    Duplicate/Copy same file N times

  11. 11

    sscanf - using same variable multiple times

  12. 12

    Presenting same RatingScale multiple times in for loop

  13. 13

    is it possible for JWT to generate a same token, two times?

  14. 14

    How to use same foreign key multiple times

  15. 15

    Recycling views shows same item multiple times

  16. 16

    How to show the same ImageView multiple times programmatically?

  17. 17

    Repeat same JS function multiple times on same page

  18. 18

    Users who are logged in more than 2 times - bash script

  19. 19

    Regex for digits not repeating more than five times in string such as contact number

  20. 20

    Get items from Ruby Array that occur 2 or more times

  21. 21

    sed a pattern followed with any single character one or more times

  22. 22

    Extracting lines appeared consecutively for 3 times or more in Linux

  23. 23

    Recall same UI View controller

  24. 24

    Constructor with more than one instance of same type

  25. 25

    Have two or more tuples with the same attribute value

  26. 26

    How to assign more ranges to same variable?

  27. 27

    JQuery: attach the same callback to one or more elements

  28. 28

    VBA - Use same variables in more modules

  29. 29

    React SVG not rerendering on attribute update

ホットタグ

アーカイブ