【问题标题】:Issue in dynamic renderUI in ShinyShiny中的动态renderUI问题
【发布时间】: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") 之前简要显示此内容。

为什么会这样?我怎样才能使它保持在选定的值?

谢谢

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    我进行了以下更改,现在似乎可以使用。它停留在选定的值上。

    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)
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-01
      • 2017-04-13
      • 2013-10-28
      • 1970-01-01
      • 2015-04-15
      • 2021-11-13
      相关资源
      最近更新 更多