【发布时间】:2015-05-04 04:40:09
【问题描述】:
我想创建一个如下所示的选择选项,
<select id="species">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>
所以我使用数据框来创建一个存储数据的表,
# Create the species table for select input.
title <- c('A', 'B', 'C')
code <- c('1', '2', '3')
species <- data.frame(title, code)
# Set choices of title and code for select input.
choicesSpecies <- setNames(species$code, species$title)
Shiny 的 ui.R,
selectInput(inputId = "species",
label = "Species:",
choices = choicesSpecies),
我收到此错误,
Error in (function (choice, name) :
All sub-lists in "choices" must be named.
这是什么意思?如何修复它以获得我需要的结果?
【问题讨论】:
-
您可以尝试使用
choices=species$code,然后使用switch语句来获取等效代码吗? -
以这种方式设置名称时是否也会发生错误(使用这种方法时我从未遇到错误):choiceSpecies
-
谢谢大家。但恐怕这些建议都不起作用......