简体   繁体   中英

Is it possible to include selectInput element in navlistPanel in R Shiny?

In my current application I am using a navlistPanel similar to the one below and I was wondering whether it would be possible to add a selectInput UI element to the navlist?

I have tried this in my ui.R but it doesn't work:

fluidPage(

 titlePanel("Application Title"),

 navlistPanel(
   "Header",
   tabPanel("First"),
   tabPanel("Second"),
   tabPanel("Third")
   # selectInput(inputId, label, choices, selected = NULL) <- I've tried this but it doesn't work
 )
)

Any solutions/workarounds are welcome.

I was wondering whether using sidebarLayout + sidebarPanel would work where the sidebarPanel imitates the behaviour of a navlistPanel but wasn't able to implement it.

A clean solution will be difficult, but how about something like this:

library(shiny)

shinyApp(
  ui <- fluidPage(
    titlePanel("Application Title"),

    navlistPanel("Header", id = "navOut",
                 tabPanel("First", "First"),
                 tabPanel(selectInput("navSel", "Selection:", c("b", "c")), textOutput("txt"))
    )
  ),
  server <- shinyServer(function(input, output){
    output$txt <- renderText(input$navSel)
  })  
)

If you are okay with using shinydashboard , it is fairly simple.

library(shiny)
library(shinydashboard)

rm(list=ls)

######/ UI Side/######

header <- dashboardHeader(title = "Test")
sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("First Tab",tabName = "FTab", icon = icon("globe")),
    menuItem("Second Tab",tabName = "STab", icon = icon("star"))
  ),
  selectInput("navSel", "Selection:", c("b","c"))
)
body <- dashboardBody()

ui <- dashboardPage(header, sidebar, body)


######/ SERVER Side/######

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

}

shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM