从特定列创建 varSelectInput

问题描述 投票:0回答:1

我有这个数据集

ao_summary

            full_name matches gender aces double_faults bp_won_pctg highlight
1    Alexander Zverev       5      M   86            21          22      TRUE
2     Aryna Sabalenka       4      F   20            17          19     FALSE
3      Ashleigh Barty       5      F   24            15          23     FALSE
4      Aslan Karatsev       6      M   54            20          34     FALSE
5     Daniil Medvedev       7      M   80            21          37     FALSE
6         Donna Vekic       4      F   15            19          18     FALSE
7     Grigor Dimitrov       5      M   51            14          23     FALSE
8      Jennifer Brady       7      F   34            17          29     FALSE
9    Karolina Muchova       6      F   17            13          29     FALSE
10  Karolina Pliskova       3      F   19            16          15     FALSE
11       Milos Raonic       4      M   82            16          17     FALSE
12        Naomi Osaka       7      F   50            22          29     FALSE
13     Novak Djokovic       7      M  103            23          37     FALSE
14    Serena Williams       6      F   35            16          27     FALSE
15 Stefanos Tsitsipas       6      M   46            17          22     FALSE

我想为

full_name
列创建一个 varSelectInput,以便能够从列表中选择玩家姓名,我该怎么做?

我尝试过:

renderUI ({
    varSelectInput(
      inputId = "PlayerName", 
      label = "Select Player", 
      data = the_data()[, c("full_name")], 
      selected = "Novak Djokovic"
    )
  })

the_data()
是在服务器中创建的反应数据。

r shiny
1个回答
1
投票

我相信你真的想要

selectInput
choices = 

library(shiny)
ui <- fluidPage(
    uiOutput('select')
        )
server <- function(input, output) {
ao_summary <- reactiveVal()
ao_summary(structure(list(full_name = c("Alexander Zverev", "Aryna Sabalenka", 
                                         "Ashleigh Barty", "Aslan Karatsev", "Daniil Medvedev", "Donna Vekic", 
                                         "Grigor Dimitrov", "Jennifer Brady", "Karolina Muchova", "Karolina Pliskova", 
                                         "Milos Raonic", "Naomi Osaka", "Novak Djokovic", "Serena Williams", 
                                         "Stefanos Tsitsipas"), matches = c(5L, 4L, 5L, 6L, 7L, 4L, 5L,
                                         7L, 6L, 3L, 4L, 7L, 7L, 6L, 6L), gender = c("M", "F", "F", "M", 
                                         "M", "F", "M", "F", "F", "F", "M", "F", "M", "F", "M"), aces = c(86L, 
                                         20L, 24L, 54L, 80L, 15L, 51L, 34L, 17L, 19L, 82L, 50L, 103L, 
                                         35L, 46L), double_faults = c(21L, 17L, 15L, 20L, 21L, 19L, 14L, 
                                         17L, 13L, 16L, 16L, 22L, 23L, 16L, 17L), bp_won_pctg = c(22L, 
                                         19L, 23L, 34L, 37L, 18L, 23L, 29L, 29L, 15L, 17L, 29L, 37L, 27L, 
                                         22L), highlight = c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, 
                                         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
                                         )), class = "data.frame", row.names = c("1", "2", "3", "4", "5", 
                                         "6", "7", "8", "9", "10", "11", "12", "13", "14", "15")))
output$select <- renderUI({
    selectInput(
        inputId = "PlayerName", 
        label = "Select Player", 
        choices = ao_summary()[, c("full_name")], 
        selected = "Novak Djokovic"
    )
})   
}
shinyApp(ui = ui, server = server)

enter image description here

然后可以在

input$PlayerName
中找到玩家姓名。

© www.soinside.com 2019 - 2024. All rights reserved.