0

I am creating a Shiny app which has a drop down list which needs to be updated based on the radio button clicked. I do update the list based on the radio button, but the last choice from the previous option still remains. I am including the code to make this more clear

  ui.R
  fluidRow(
                            column(3,
                                   radioButtons("matchType", label = h3("Match type"),
                                                choices = list("Test" = "Test",
                                                               "ODI" = "ODI", 
                                                               "Twenty20" = "TT"), 
                                                inline=TRUE,
                                                selected = "Test"),
                                   selectizeInput(
                                       "batsman", label = "Players", choices = NULL, multiple=FALSE,selected="tendulkar",
                                       options = list(create = TRUE,placeholder = 'Choose the player',size=12)

                                   ),
                                   selectizeInput(
                                       "batsmanFunc", label = "Choose chart type", choices = NULL, multiple=FALSE,selected="4s of batsman",
                                       options = list(create = TRUE,placeholder = 'Choose the chart')

                                   )

                            ),

I have set up server.R as follows

 server.R

 output$batsmanPlot <- renderPlot({  
    # Include the list to display in the drop downs on choice of matchType
    if(input$matchType == "Test"){

        updateSelectizeInput(session, 'batsman', choices = testBatsman, server = TRUE,selected=input$batsman)
        updateSelectizeInput(session, 'batsmanFunc', choices = funcs, server = TRUE,selected=input$batsmanFunc)

    } else {

        updateSelectizeInput(session, 'batsman', choices = odiBatsman, server = TRUE,selected=input$batsman)
        updateSelectizeInput(session, 'batsmanFunc', choices = funcsODITT, server = TRUE,selected=input$batsmanFunc)
    }
    print(input$batsman)
    analyzeBatsman(input$batsman,input$batsmanFunc,input$matchType)

})

There are 2 issues 1) Since I use selected=input$batsman, the drop down is blank initially. If I chose a fixed value for this, then every time choose another value it displays the new value and then returns back to the selected value. I think this is because updateSelectize is inside renderPlot

2) When I switch between radio buttons "Test"/"ODI", the last selected player is not cleared out. The new list is appended to the last selected player. The next time around, it is the actual list.

How can this be addressed?

Tinniam V. Ganesh
  • 1,979
  • 6
  • 26
  • 51
  • I think you are looking for renderUI: http://shiny.rstudio.com/articles/dynamic-ui.html – Chris Nov 26 '15 at 17:05
  • Also a good overview here: http://stackoverflow.com/questions/21465411/r-shiny-passing-reactive-to-selectinput-choices/21467399#21467399 – Chris Nov 26 '15 at 17:07
  • @Chris - Let me take a look of renderUi – Tinniam V. Ganesh Nov 26 '15 at 17:20
  • @Chris - I made the change. Now I get dynamic UI but when I select from the drop downs it does what it needs to do and then resets back to the 1st value. I have included this in another thread http://stackoverflow.com/questions/33973300/issue-in-dynamic-renderui-in-shiny Would you know how to fix this? Thanks – Tinniam V. Ganesh Nov 28 '15 at 16:03

0 Answers0