Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input binding to get the currently selected item in the sidebar #17

Open
DivadNojnarg opened this issue Apr 11, 2020 · 1 comment
Open
Assignees

Comments

@DivadNojnarg
Copy link
Collaborator

DivadNojnarg commented Apr 11, 2020

In the meantime, we may use shiny.setInputValue:

library(shiny)
library(gentelellaShiny)


options(shiny.jquery.version=1)
shinyApp(
  ui = gentelellaPageCustom(
    title = "Shiny Gentelella",
    navbar = gentelellaNavbar(),
    sidebar = gentelellaSidebar(
      sidebarProfile(
        name = "Mark",
        img = "https://image.flaticon.com/icons/svg/236/236831.svg"
      ),
      sidebarDate(),
      sidebarMenu(
        sidebarItem(
          "Tab 1",
          tabName = "tab1"
        ),
        sidebarItem(
          "Tab 2", 
          tabName = "tab2"
        )
      )
    ),
    body = gentelellaBody(
      tabItems(
        tabItem(
          tabName = "tab1",
          tags$head(
            tags$script(
              "$(function() {
                $('li a').on('click', function() {
                  var val = $(this).attr('data-value');
                  Shiny.setInputValue('currentTab', val);
                });
                // trigger click on the first item
                setTimeout(function(){
                  $('li a').first().trigger('click');
                }, 10);
              });
              "
            )
          ),
          "Tab 1 content"
        ),
        tabItem(
          tabName = "tab2",
          "Tab 2 content"
        )
      )
    ),
    footer = gentelellaFooter()
  ),
  server = function(input, output, session) {
    observe(print(input$currentTab))
  }
)

See here to get the related post

@DivadNojnarg DivadNojnarg self-assigned this Apr 11, 2020
@Sebastianlecoz
Copy link

Sebastianlecoz commented Jan 24, 2022

Hi,
I'm new to css and html. Is it normal this does not work with dynamic tabs ?

Here is my example :

library(shiny)
library(gentelellaShiny)


options(shiny.jquery.version=1)
shinyApp(
  ui = gentelellaPageCustom(
    title = "Shiny Gentelella",
    navbar = gentelellaNavbar(),
    sidebar = gentelellaSidebar(
      sidebarProfile(
        name = "Mark",
        img = "https://image.flaticon.com/icons/svg/236/236831.svg"
      ),
    sidebarDate(),
    sidebarMenu(


        uiOutput("tab11"),

        uiOutput("tab22")
     
    )
  ),
  body = gentelellaBody(
    tabItems(
      tabItem(
        tabName = "tab1",
        tags$head(
          tags$script(
            "$(function() {
              $('li a').on('click', function() {
                var val = $(this).attr('data-value');
                Shiny.setInputValue('currentTab', val);
              });
              // trigger click on the first item
              setTimeout(function(){
                $('li a').first().trigger('click');
              }, 10);
            });
            "
          )
        ),
        "Tab 1 content"
      ),
      tabItem(
        tabName = "tab2",
        "Tab 2 content"
      )
    )
  ),
  footer = gentelellaFooter()
),
server = function(input, output, session) {
  observe(print(input$currentTab))

  output$tab22 <- renderMenu({
  
    sidebarItem(" item 1", tabName = "tab2",
     icon =  tags$i(class = "fas fa-exchange-alt", style = "color: rgb(255,255,255)"))
 
    
  })
  output$tab11 <- renderMenu({
  
    sidebarItem("Item 2", tabName = "tab1",
    icon =  tags$i(class = "fas fa-exchange-alt", style = "color: rgb(255,255,255)"))
  
    
  })
  
}
)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants