Understanding values stored in input widgets

12 views
Skip to first unread message

Rohit Saluja

unread,
Jan 8, 2018, 9:12:29 AM1/8/18
to Shiny - Web Framework for R

I am trying to understand the value stored in shiny inputwidgets. I have written below code which outputs a sliderInput and based on the value of sliderInput, another o/p element is generated i.e.

If sliderInput value > 30 then it generates groupedradiobutton else it generates a file upload button



library(shiny)
library(shinyWidgets)
ui <- fluidPage(
  sliderInput(inputId = "num", 
              label = "Choose a number", 
              value = 25, min = 1, max = 100),
  uiOutput("uploadorSelect"),
  textOutput("RadioButtonValue")
)

server <- function(input, output) {
  output$uploadorSelect <- renderUI({
    x<-input$num

    if( x > 30 ){
      # render grouped radio buttons  
      radioGroupButtons(inputId = "opbAppendRemoveMonthlyOption",choices =c("Append","Continue"), status = "success",
                        direction = "horizontal",justified = F,checkIcon = list(yes=icon("ok",lib="glyphicon")),selected = character(0))

    }else{
      # render upload button
      fileInput(inputId="btnUploadMonthlyFile",label = "Upload Monthly Data file") 
    }
  })

  output$RadioButtonValue<-renderText({
    x<-(input$opbAppendRemoveMonthlyOption)
    return(x)

  })
}

shinyApp(ui = ui, server = server)


Situation:-

Step 1 - I changed the value of sliderInput to 31 which generates groupedradiobutton and then I select Append from the radiobutton

Step 2 - I again changed the value of sliderInput to 32 which regenerates the groupedradiobutton, which I believe should reset the value of input$opbAppendRemoveMonthlyOption used in output$RadioButtonValue block as Null, but instead of that it still retains the value selected in Step1

I think this is due to the fact that when I refer input$opbAppendRemoveMonthlyOption in output$RadioButtonValue it returns the cached value? if that is so how can set the value to default every time I change the value of sliderInput?

Reply all
Reply to author
Forward
0 new messages