【发布时间】:2018-06-17 12:39:34
【问题描述】:
我试图了解shiny inputwidgets 中存储的值。我在下面编写了输出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,这会生成分组单选按钮,然后我从单选按钮中选择 Append
第 2 步 - 我再次将 sliderInput 的值更改为 32,这会重新生成 groupedradiobutton,我认为这应该将 output$RadioButtonValue 块中使用的 input$opbAppendRemoveMonthlyOption 的值重置为 Null,但它仍然保留选择的值在第一步
我认为这是因为当我在 output$RadioButtonValue 中引用 input$opbAppendRemoveMonthlyOption 时,它会返回缓存的值?如果是这样,每次更改sliderInput的值时如何将值设置为默认值?
【问题讨论】:
-
好的,在仔细阅读您的问题后,我想您所期望的是,如果您将滑块调整为 N>30,并选择一个单选按钮值;重新调整滑块后,是否应该重置“追加”/“继续”状态?目前,当我按原样运行您的脚本时,这是行为,无法重现您的错误。
标签: r shiny shiny-reactivity