change_bgcolor_tab: change_bgcolor_tab

Description Usage Details Author(s) Examples

View source: R/change_bgcolor_tab.R

Description

change_bgcolor_tab changes the background color of a tabPanel in a tabSetPanel

Usage

1
change_bgcolor_tab(tabId, subTabNumber, color)

Details

This function shoudl be used inside server.R of a shiny app.

Author(s)

Javier Saez Gallego

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require(shiny)
require(shinyjs)
require(devtools)
require(shinyColors)

shinyApp(
  ui = fluidPage(
    useShinyjs(),
    mainPanel(
      h4('The colors of the tabs react to the numeric inputs.'),
      tabsetPanel(
        id = "tabSetId",
        tabPanel(
          "Input must be positive",
          numericInput('numPos', label = "This number should be > 0", value = -1)
        ),
        tabPanel(
          "Input must be negative",
          numericInput('numNeg', label = "This number should be < 0", value = 1)
        )
      )
    )),

  server = function(input, output) {
    observeEvent(input$numPos, {
      # Change the color of the tab when numPos is negative
      if (input$numPos <= 0) {
        change_color_tab("tabSetId", 1, 'red')
      } else{
        change_color_tab("tabSetId", 1, 'black')
      }
    })

    observeEvent(input$numNeg, {
      # Change the background color of the tab when numNeg is positive
      if (input$numNeg >= 0) {
        change_bgcolor_tab("tabSetId", 2, '#ffc266')
      } else{
        change_bgcolor_tab("tabSetId", 2, 'white')
      }
    })
  }
)

jsga/shinyFiddle documentation built on May 20, 2019, 2:08 a.m.