Created
September 12, 2013 11:56
-
-
Save stla/6536230 to your computer and use it in GitHub Desktop.
Series of tabs with Shiny - test 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mytabsetPanel <- function (tabs, id = NULL, selected = NULL) | |
| { | |
| #tabs <- list(...) | |
| tabNavList <- tags$ul(class = "nav nav-tabs", id = id) | |
| tabContent <- tags$div(class = "tab-content") | |
| firstTab <- TRUE | |
| tabsetId <- as.integer(stats::runif(1, 1, 10000)) | |
| tabId <- 1 | |
| for (divTag in tabs) { | |
| thisId <- paste("tab", tabsetId, tabId, sep = "-") | |
| divTag$attribs$id <- thisId | |
| tabId <- tabId + 1 | |
| tabValue <- divTag$attribs$`data-value` | |
| if (!is.null(tabValue) && is.null(id)) { | |
| stop("tabsetPanel doesn't have an id assigned, but one of its tabPanels ", | |
| "has a value. The value won't be sent without an id.") | |
| } | |
| liTag <- tags$li(tags$a(href = paste("#", thisId, sep = ""), | |
| `data-toggle` = "tab", `data-value` = tabValue, divTag$attribs$title)) | |
| if (is.null(tabValue)) { | |
| tabValue <- divTag$attribs$title | |
| } | |
| if ((firstTab && is.null(selected)) || (!is.null(selected) && | |
| identical(selected, tabValue))) { | |
| liTag$attribs$class <- "active" | |
| divTag$attribs$class <- "tab-pane active" | |
| firstTab = FALSE | |
| } | |
| divTag$attribs$title <- NULL | |
| tabNavList <- tagAppendChild(tabNavList, liTag) | |
| tabContent <- tagAppendChild(tabContent, divTag) | |
| } | |
| tabDiv <- tags$div(class = "tabbable", tabNavList, tabContent) | |
| } | |
| #### | |
| #### Server | |
| #### | |
| shinyServer(function(input, output, session) { | |
| texts <- c("blabla", "HHHHHHHH") | |
| nodes <- c("aaa","bbb") | |
| #for(i in 1:2){ ## THAT DOESN'T WORK WITH THIS LOOP !!! | |
| # text <- texts[i] | |
| # output[[nodes[i]]] <- renderText({text}) | |
| #} | |
| output[[nodes[1]]] <- renderText({texts[1]}) | |
| output[[nodes[2]]] <- renderText({texts[2]}) | |
| # | |
| tabnames <- c("uuu", "vvv") | |
| output$twotabs <- renderUI({ | |
| tabs <- list(NULL) | |
| for(i in 1:2){ | |
| tabs[[i]] <- tabPanel(tabnames[i], textOutput(nodes[i])) | |
| } | |
| mytabsetPanel( | |
| tabs | |
| , id="tab0") | |
| }) | |
| # | |
| #output$text1 <- renderUI({ textOutput(nodes[1]) }) | |
| #output$text2 <- renderUI({ textOutput(nodes[2]) }) | |
| # | |
| # tag selection (optional) : | |
| observe({ | |
| tabselect <- input$tab == TRUE | |
| if (tabselect) { | |
| updateTabsetPanel(session, "tab0", "uuu") | |
| } else { | |
| updateTabsetPanel(session, "tab0", "vvv") | |
| } | |
| }) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shinyUI(pageWithSidebar( | |
| headerPanel("xxx"), | |
| ## | |
| ## sidebar panel | |
| ## | |
| sidebarPanel( | |
| checkboxInput("tab", "select tab") | |
| ), | |
| ## | |
| ## main panel | |
| ## | |
| mainPanel( | |
| #uiOutput("text1"), | |
| #uiOutput("text2") | |
| uiOutput("twotabs") | |
| ) | |
| )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment