0

It appears the input value of a selectInput object is not updating. I have inserted one in the sidebar menu. I am using shinyDashboard. here is my code.

header & Sidebar

header <-
  dashboardHeader(
    title = "REPORT",
    tags$li(class = "dropdown",
            tags$style(
              HTML(
                "@import url('//fonts.googleapis.com/css?family=Libre+Baskerville:400,700|Open+Sans:400,700|Montserrat:400,700');"
              )
            )),
    disable = FALSE,
    titleWidth  = '200'
  )
header$children[[3]]$children[[3]] <-
  tags$h1("DATABASE",
          # align = 'left',
          style = "color:#FFFFFF; font-weight: bold; font-family: 'Open Sans','Libre Baskerville',Montserrat, serif;font-size: 23px;")

data_type_list<-c('in vivo','in vitro','pbpk') 
siderbar <- dashboardSidebar(
    width = 200,
    sidebarMenu(
        id = 'sidebar',
        style = "position: relative; overflow: visible;",
        menuItem(
            "TK Knowlegebase",
            tabName = 'tk',
            icon = icon('database'),
            badgeColor = "teal",
            #radioButtons("tk_data_type", "Select Data Type:",data_type_list)
            selectInput('tk_data_type',"Select Data Type",data_type_list, selected=1)
        )
    )
)

body

body <- dashboardBody(width = 870,
                      tags$head(
                          tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")
                      ),
                      #theme = shinythemes::shinytheme("darkly"),
                      tabItems(
                          tabItem (
                              tabName = "tk",
                              mainPanel(
                    
                                  #in vivo ----
                      conditionalPanel(
                          condition ="input.tk_data_type== 'in vivo'",
                          tags$h2('vivo')
                                  ),
                      
                      # in vitro ----
                      conditionalPanel(
                          condition="input.tk_data_type== 'in vitro'",
                          tags$h2('vitro')
                          )
                       ,
                      #  pbpk ----
                      conditionalPanel(
                          condition="input.tk_data_type== 'pbpk'",
                              tags$h2('pbpk')              
                         )
                    
)))

server = function(input, output, session) {
observe({input$tk_data_type})
}
ui <- dashboardPage(title = 'ARC Toxkin App', skin = 'purple',
                    header, siderbar, body)
shiny::shinyApp(ui = ui, server = server)

I even attempted to use observe({input$tk_data_type}) in the server section to no success.

What I obtain is a blank page. what I wish to see is content from dashboardBody() appear.

Thank you for your time

UPDATE This is a short-term fix solution, thanks to user YBS.

vitro_tabset<-tabsetPanel(
    tabPanel("Detailed",
             "This is a test"),
    tabPanel("Phys-chem",
             "This is a test"),
    tabPanel("Exploratory",
             "This is a test"),
    tabPanel("Downloads",
             "This is a test")
)
vivo_tabset<-tabsetPanel(
    tabPanel("Detailed",
             "This is a test"),
    tabPanel("Phys-chem",
             "This is a test"),
    tabPanel("Exploratory",
             "This is a test"),
    tabPanel("Downloads",
             "This is a test")
)


siderbar <- dashboardSidebar(
    sidebarMenu(
        id = 'sidebar',
        menuItem(
            "TK Knowlegebase",
            tabName = 'tk',
            icon = icon('database'),
            badgeColor = "teal",
            selected = TRUE,
            startExpanded = TRUE,
            #radioButtons("tk_data_type2", "Select Data Type:",data_type_list),
            menuSubItem('vivo', tabName = 'vivo', icon = shiny::icon("angle-double-right"), selected = NULL),
            menuSubItem('vitro', tabName = 'vitro', icon = shiny::icon("angle-double-right"), selected = TRUE),
            menuSubItem('pbpk', tabName = 'pbpk', icon = shiny::icon("angle-double-right"), selected = NULL)
        )
    )
)

body <- dashboardBody(width = 870,
                      tabItems(
                          tabItem (tabName = "vivo",
                                     vivo_tabset),
                          tabItem(tabName='vitro',
                                # in vitro ----
                                vitro_tabset),
                          #  pbpk ----
                          tabItem(tabName='pbpk')
  • For someone to help you please post a minimally reproducible example. From the code above, there is no way to know how you are defining `data_type_list`. Please see here https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – YBS Oct 01 '20 at 02:30
  • My apologies. I just updated my code. – Maad scientist Oct 01 '20 at 03:54

1 Answers1

0

It appears that tabItems() and tabItem() don't work well in your program as the sidebarmenu requires minor tweaking. Also, you don't need mainPanel. Try this

data_type_list <- c("in vivo","in vitro","pbpk")

ui <- shinydashboard::dashboardPage(title = "ARC Toxkin App",  skin = "purple",
                      shinydashboard::dashboardHeader(
                      title = "REPORT" ,
                      tags$li(class = "dropdown",
                              tags$style(
                                HTML(
                                  "@import url('//fonts.googleapis.com/css?family=Libre+Baskerville:400,700|Open+Sans:400,700|Montserrat:400,700');"
                                )
                              )),
                      disable = FALSE,
                      titleWidth  = '200'
                    ),

                    shinydashboard::dashboardSidebar(width = 220,
                                                     useShinyjs(),
                      sidebarMenu(
                        id = "tabs",
                        style = "position: relative; overflow: visible;",
                        menuItem("TK Knowlegebase", tabName="tk", icon = icon("bar-chart-o"),
                          menuSubItem("TK Knowlegebase1", tabName = "tk1", icon = icon('database')),
                          selectInput("tk_data_type", label="Select Data Type", choices = data_type_list, selected=1),
                          menuSubItem("TK Knowlegebase2", tabName = "tk2", icon = icon('database'))
                          #radioButtons("tk_data_type2", "Select Data Type:",data_type_list)
                        )
                      )
                    ),

                    shinydashboard::dashboardBody( #width = 870,
                      tags$head(
                        tags$link(rel = "stylesheet", type = "text/css", href = "custom.css"),
                      ),
                      #theme = shinythemes::shinytheme("darkly"),
                      tabItems(
                        #tabItem(tabName = "tk", headerPanel('First')),
                        tabItem(tabName = "tk1",
                                fluidRow(
                                  shinydashboard::box(title = "Graphics Package", width = 12, solidHeader = TRUE, status="info",
                                  ## vivo
                                  conditionalPanel(
                                    condition = "input.tk_data_type == 'in vivo'",
                                    tags$h2(' vivo')
                                  ),

                                  ## in vitro
                                  conditionalPanel(
                                    condition = "input.tk_data_type == 'in vitro'",
                                    tags$h2(' vitro')
                                  ),
                                  ##  pbpk
                                  conditionalPanel(
                                    condition = "input.tk_data_type == 'pbpk'",
                                    tags$h2(' pbpk')
                                  ),
                                  verbatimTextOutput("tb1"),
                                  DTOutput("tb2")
                                  
                                ))
                         ),
                         tabItem(tabName = "tk2", headerPanel('Last'), DTOutput("tb3")
                                 #verbatimTextOutput("tb4")
                         )
                    )
      )
)


server <- function(input, output, session) {

  output$tb3 <- renderDT(mtcars)
  output$tb2 <- renderDT(iris)
  output$tb1 <- renderPrint({input$tk_data_type})
  output$tb4 <- renderPrint({input$tk_data_type2})

}

shinyApp(ui, server)
YBS
  • 19,324
  • 2
  • 9
  • 27
  • thank you for this response. Unfortunately, this is for work and it is necessary that I have tabItems and tabItem. – Maad scientist Oct 02 '20 at 22:38
  • I definitely agree that somehow shinyDashboard is disabling selectInput when put inside sidebar() – Maad scientist Oct 02 '20 at 22:42
  • In a situation where selectInput is a long list, menuSubItems would not be a good solution. the fact is selectInput just does not work in the sidebar for some reason(input value is null) – Maad scientist Oct 03 '20 at 20:21
  • I am not sure of the problem, as it does work in the example above. In fact, you can change `menuSubItem` to `menuItem`, and it will still work. Please make sure of the order. If you are using user supplied data to display choices, then you need to process on the server side in `renderUI` and display using `uiOutput` in the body. – YBS Oct 03 '20 at 20:59
  • I agree for this case. I do have however another app where the select menu has 50 items. In that case, It is not realistic to generate 30 submenus even if generated automatically with renderUI. I just wish I knew how to make the selectInput work in the sidebar. – Maad scientist Oct 04 '20 at 00:37
  • Perhaps you should consider displaying selectInput in the rightsidebar using shinydashboardPlus. For each selected menuItem you can display the corresponding selectInput in the rightsidebar. Just a suggestion. – YBS Oct 04 '20 at 00:42