微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将自定义数量的 tabPanel 添加到闪亮仪表板中的 tabsetPanel

如何解决将自定义数量的 tabPanel 添加到闪亮仪表板中的 tabsetPanel

我正在尝试使用基于变量 tabsetPanel 的多个 tabPanel 来创建 form。我已经尝试了下面的代码,但出现了一些错误

attr(x,"selected") 中的错误

有人可以帮助我好吗?

library(shinydashboard)
library(tidyverse)

form <- 2

ui <- dashboardPage(
    title = "Rolê de Aventura",skin="blue",dashboardHeader(titleWidth = 1024,title=list(title=tags$img(src="logoPQ.png",heigth=45,width=45,align="left"),title=tags$p(style="text-align:center;","Rolê de Aventura")
                    )
    ),dashboardSidebar(
        selectInput("categoria",label = "Categoria:",choices = list("Quarteto Misto","Dupla Masculina","Dupla Mista","Dupla Feminina"),width="200px"
        )
    ),dashboardBody(
        textInput("equipe","Nome da equipe:",width = NULL),tabsetPanel(width = NULL,type = "tabs",do.call(tabsetPanel,c(width=NULL,type="tabs",lapply(1:form,function(i) {
                                               tabPanel(title = str_c("Atleta",i),textInput(str_c("atleta","Nome:",width=NULL),dateInput(str_c("at.nasc","Nascimento:",width="30%"),checkBoxGroupInput(str_c("at.sex","Sexo:",width="30%",choices=list("Masculino","Feminino")))
                                           })
                    )
                    )
        )
    )
)

server <- function(input,output) {
}

shinyApp(ui = ui,server = server)

解决方法

我似乎无法准确识别您的错误。然而,有一个答案here

我已经相应地修改了您的代码,它按预期工作。见下文,

library(shinydashboard)
library(tidyverse)
library(shiny)

form <- 2

ui <- dashboardPage(
        title = "Rolê de Aventura",skin="blue",dashboardHeader(titleWidth = 1024,title=list(title=tags$img(src="LogoPQ.png",heigth=45,width=45,align="left"),title=tags$p(style="text-align:center;","Rolê de Aventura")
                        )
        ),dashboardSidebar(
                selectInput("categoria",label = "Categoria:",choices = list("Quarteto Misto","Dupla Masculina","Dupla Mista","Dupla Feminina"),width="200px"
                )
        ),dashboardBody(
                textInput("equipe","Nome da equipe:",width = NULL),do.call(
                        tabsetPanel,c(
                                id = "t",lapply(
                                        1:form,FUN = function(x) {
                                                tabPanel(
                                                        title = paste("tab",x)
                                                )
                                                
                                        }
                                )
                        )
                )
        )
)

server <- function(input,output) {
}

shinyApp(ui = ui,server = server)
,

我发现在这种情况下将 exec() 函数与 !!! 一起使用很有用。

library(shinydashboard)
library(tidyverse)
library(shiny)

form <- 2

#store the ui code in a list to use later.

tabs <- map(1:form,function(i) {
          tabPanel(title = str_c("Atleta",i),textInput(str_c("atleta","Nome:"),dateInput(str_c("at.nasc","Nascimento:",width="30%"),checkboxGroupInput(str_c("at.sex","Sexo:",width="30%",choices=c("Masculino","Feminino")))
        })

ui <- dashboardPage(
  title = "Rolê de Aventura","Rolê de Aventura")
                  )
  ),dashboardSidebar(
    selectInput("categoria",width="200px"
    )
  ),dashboardBody(
    textInput("equipe","Nome da equipe:"),exec(tabsetPanel,!!!tabs))
    )


server <- function(input,server = server)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?