我试图了解存储在shiny inputwidgets
. 我在下面编写了输出a的代码,sliderInput
并且基于sliderInput的值,生成了另一个o / p元素,即
如果sliderInput
value > 30 那么它会生成 groupedradiobutton 否则它会生成一个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)
情况:-
第 1 步 - 我将 sliderInput 的值更改为 31,这会生成 groupedradiobutton,然后我Append
从 radiobutton 中进行选择
第 2 步 - 我再次将滑块输入的值更改为 32,它重新生成分组单选按钮,我认为应该将块中input$opbAppendRemoveMonthlyOption
使用的值重置output$RadioButtonValue
为 Null,但它仍然保留在第 1 步中选择的值
我认为这是因为当我引用 它input$opbAppendRemoveMonthlyOption
时output$RadioButtonValue
返回缓存值?如果是这样,每次更改sliderInput的值时如何将值设置为默认值?