gpt4 book ai didi

R Shiny : selectInput - pieces of javascript appear in UI

转载 作者:行者123 更新时间:2023-12-02 04:17:03 25 4
gpt4 key购买 nike

目标是显示 selectInput 输入的列表。该列表显示正确,但在每个单独的输入菜单的名称旁边(本例中为“a”、“b”、“c”)显示以下字符串:“div form-groupshiny-input-container”。我非常感谢您提示为什么会发生这种情况!

屏幕截图:

enter image description here

ui.R

shinyUI(
htmlOutput("tabs")
)

服务器.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
})
})

提前致谢!

博格丹

最佳答案

您好,这是因为 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'

关于R Shiny : selectInput - pieces of javascript appear in UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33067200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com