R Shiny : selectInput - pieces of javascript appear in UI

标签 r shiny

目标是显示 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/

相关文章:

r - 如何设置ggvis默认使用canvas渲染器?

R中的RMSE(均方根偏差)计算

javascript - 如何在鼠标悬停时的弹出窗口中显示放大的图像,或者在 RShiny 的 rhandsontable 单元格中显示的图像上的单击事件上显示放大的图像?

r - 在 Azure 中创建运行 R 脚本的管道,而无需通用化 VM

r - 在 Shiny 应用程序中逐步浏览 n 个屏幕或轮播

R Shiny 动态过滤

r - 全局变量和无功值之间的差异

javascript - 在 R shiny 中加载页面时调用 javascript 函数

r - 查看两个变量的符号是否不同 - 满足 R 中的条件

r - 在 R 中实现幂方法时的无限递归