Функция отладки Tabset `* tmp *` [[i]]: индекс за пределами - PullRequest
0 голосов
/ 03 января 2019

Я ищу, чтобы отладить ошибку, которую я получаю в функции, созданной для манипулирования цветами вкладок для R блестящих приложений.Я попытался сделать некоторые манипуляции с вкладкой <- list (...), но не смог определить причину ошибки.</p>

Функция работает с той же структурой, что и функция tabsetPanel, с добавлением tabcolors, которая принимает список цветов, которые должны соответствовать длине вкладок в tabsetPanel.

    tabsetPanel2 = function (
  ..., id = NULL, selected = NULL, type = c("tabs", "pills"),
  position = c("above", "below", "left", "right"), tabcolors = NULL, 
title = NULL) {
  if(is.null(colors)){
    returner = tabsetPanel(..., id, selected, type, position)
  } else {
    tabs <- list(...)
    if(length(tabs) != length(tabcolors)){stop("The number of colors 
must match the number of tabs")}
    type <- match.arg(type)
    tabset <- buildTabset(tabs, paste0("nav nav-", type), NULL, id, 
 selected)
     for (i in 1:length(tabcolors)){
      tabset$navList$children[[i]]$children[[1]]$attribs$style = 
paste0("background-color: ",tabcolors[i],";")
      tabset$content$children[[i]]$attribs$style = paste0("border: 
4px solid", tabcolors[i],";")
    }

    tabset$navList$attribs$class = 
paste0(tabset$navList$attribs$class," nav-stacked col-xs-2")
    tabset$navList$attribs$style = "padding-right: 0px;"
    tabset$content$attribs$class = 
paste0(tabset$content$attribs$class," col-xs-10")
    tabset$content$attribs$style = "padding-right: 0px; padding- 
   left: 0px;"

    position <- match.arg(position)
    if (position %in% c("above", "left", "right")) {
      first <- tabset$navList
      second <- tabset$content
    } else if (position %in% c("below")) {
       first <- tabset$content
      second <- tabset$navList
    }

    if(!is.null(title)){
      first$children[[length(tabcolors)+1]] = div(title)
      first$children = first$children[c(length(tabcolors) + 1, 1: 
   (length(tabcolors)))]
     }

    returner = tags$div(class = paste("tabbable tabs-", position, 
 sep = ""), first, second)

   }
  return(returner)
 }
 environment(tabsetPanel2) = environment(tabsetPanel)

То, что раньше было рабочим примером.

UI

library(shiny)
shinyUI(fluidPage(
uiOutput("tweak"),

  tabsetPanel2(
    id = "MainTabs", 
    type = "tabs", 
    position = "left", 
    tabcolors = c("#FFAAAA","#AAFFAA","#AAAAFF"),
    title = "Colorful Tabs",
    tabPanel(title = "Tab1", "This is tab 
1.",tags$br(),tags$br(),tags$br(),tags$br(),tags$br(),tags$br()),
    tabPanel(title = "Tab2", "This is tab 
2.",tags$br(),tags$br(),tags$br(),tags$br(),tags$br(),tags$br()),
    tabPanel(title = "Tab3", 
             tabsetPanel(
               id = "stuff",
                type = "tabs",
               position = "above",
                tabPanel(title = "InnerTab1", "This is inner tab 1"),
               tabPanel(title = "InnerTab2", "This is inner tab 2")
            ))
   )
))

Сервер

library(shiny)
shinyServer(function(input, output) {

output$tweak = renderUI({
tagList(list(tags$head(tags$style(HTML("
tabs-left > .nav-tabs{
border-bottom-width: 0px;
    }
tabs-left > .nav-tabs > li{
margin-right: 0px;
}
 tabs-left > .nav-tabs > li > a{
margin-right: 0px;
border-right-width: 0px;
border-radius: 10px 0px 0px 10px;
border-top-width: 0px;
border-bottom-width: 0px;
border-left-width: 5px;
}
tabs-left > .nav-tabs > li.active{
margin-right: 0px;
}
tabs-left > .nav-tabs > li.active > a, 
tabs-left > .nav-tabs > li.active > a:focus, 
tabs-left > .nav-tabs > li.active > a:hover{
margin-right: 0px;
border-radius: 10px 0px 0px 10px;
border-right-width: 0px;
border-top-width: 0px;
border-bottom-width: 0px;
border-color: blue;
border-left-width: 5px;
}
")))))
  })

 })
...