目标是显示selectInput输入列表。列表正确显示但在每个单独输入菜单的名称旁边(本例中为'a','b','c'),显示以下字符串:'div form-group shiny-input-container'。我非常感谢提示为什么会发生这种情况!
截图:
ui.R
shinyUI(
htmlOutput("tabs")
)
server.R
shinyServer(function(input, output, session) {
output$tabs<-renderUI({
navbarPage("MyApp",tabPanel("Tab",htmlOutput("myoutput")))
})
output$myoutput<-renderUI({
datavector<-c('one','two','three')
outputlist<-list()
for (i in 1:3) {
output<-selectInput(paste("selection",i,sep=""), c('a','b','c')[i],
c("one"=1,"two"=2,"three"=3),
selected=datavector[i])
outputlist<-append(outputlist,output)
}
outputlist
})
})
提前致谢!
的Bogdan
答案 0 :(得分:3)
你好,因为append
没有按照你想要的方式处理列表元素,而是使用list
:
output$myoutput<-renderUI({
datavector<-c('one','two','three')
outputlist<-list()
for (i in 1:3) {
output<-selectInput(paste("selection",i,sep=""), c('a','b','c')[i],
c("one"=1,"two"=2,"three"=3),
selected = datavector[i])
outputlist <- list(outputlist, output)
}
outputlist
})
尽管如此,我仍然建议您使用lapply
,它更清晰:
output$myoutput<-renderUI({
datavector<-c('one','two','three')
lapply(X = 1:3, FUN = function(i) {
selectInput(paste("selection",i,sep=""), c('a','b','c')[i],
c("one"=1,"two"=2,"three"=3),
selected=i)
})
})
注意:我将selected = datavector[i]
替换为selected = i
,因为:
'selected' must be the values instead of names of 'choices' for the input 'selection'