【问题标题】:How can I create a list from a matrix using Shiny?R / Shiny:我怎样才能从矩阵中做一个列表?
【发布时间】:2014-02-27 18:40:20
【问题描述】:

我有以下矩阵:

   Country Sp 
1 Portugal Cc 
2    Spain Cc 
3   France Cc 
4    Italy Cm 

如果我这样做:

selectInput("country", "Country:", choices=NestingArea$Country)

我将获得 4 个国家/地区的列表。但是,如果我只想列出“Sp==Cc”的国家(葡萄牙、西班牙和法国),我应该怎么做?

【问题讨论】:

  • 听起来像一个简单的子集练习...试试selectInput( "country", "Country:", choices=subset(NestingArea, Sp=='Cc', 1))

标签: r shiny conditional-statements selectinputdate


【解决方案1】:
NestingArea <- data.frame(Country = c("Portugal", "Spain", "France", "Italy"),
                 Sp = c("Cc", "Cc", "Cc", "Cm"))

您可以获得所需的国家/地区子集:

NestingArea$Country[NestingArea$Sp == "Cc"]
#> [1] "Portugal" "Spain"    "France"

因此,解决方案是:

selectInput("country", "Country:", choices=NestingArea$Country[NestingArea$Sp == "Cc"])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    相关资源
    最近更新 更多