【发布时间】:2015-11-28 15:55:41
【问题描述】:
我正在使用 renderUI() 来显示动态 UI。下拉列表框是动态更新的,但是当我从下拉列表中选择一个特定值时,它确实需要,但会退回到列表中的第一个元素。为什么会这样?为什么不能停留在选定的值。
ui.R
fluidRow(
column(3,
radioButtons("matchType", label = h3("Match type"),
choices = list("Test" = "Test",
"ODI" = "ODI",
"Twenty20" = "TT"),
inline=TRUE,
selected = "Test"),
uiOutput("players"),
uiOutput("functions")
),
server.R
testBatsman <- c("X","Y","Z")
odiBatsman <- c("XX","YY","ZZ")
funcs <- c("A","B","C")
funcsODITT <- c("AA","BB","CC")
output$batsmanPlot <- renderPlot({
# Include the list to display in the drop downs on choice of matchType
if(input$matchType == "Test"){
player = testBatsman
f = funcs
} else if(input$matchType == "ODI"){
player = odiBatsman
f = funcsODITT
}
output$players = renderUI({
selectInput('batsman', 'Columns',choices=player)
})
output$functions = renderUI({
selectInput('batsmanFunc', 'Column1',choices=f)
})
print(input$batsman)
analyzeBatsman(input$batsman,input$batsmanFunc,input$matchType)
虽然它能够动态调整 2 个下拉菜单,但它会返回到所选列表的第一个元素。例如,当 testBatsman('Z') 和 funcs('C") 它会在返回到 testBatsman('X') 和 funcs("A") 之前简要显示此内容。
为什么会这样?我怎样才能使它保持在选定的值?
谢谢
【问题讨论】: