我正在使用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个下拉列表,但它会返回到所选列表的第一个元素。对于e,g当 testBatsman('Z')和funcs('C“)在返回testBatsman('X')和funcs(”A“)之前会短暂显示。
为什么会这样?如何使其保持选定的值?
由于
答案 0 :(得分:0)
我做了以下更改,现在似乎工作了。它保持在选定的值上。
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
}
else {
player = ttBatsman
f = funcsODITT
}
output$players = renderUI({
selectInput('batsman', 'Columns',choices=player,selected=input$batsman)
})
output$functions = renderUI({
selectInput('batsmanFunc', 'Column1',choices=f,selected=input$batsmanFunc)
})