Reputation: 326
I have a sliderInput
in a menuItem
which can be moved and the selected number needs to be displayed on the screen. Below is the code:
library(shiny)
library(shinydashboard)
sidebar <- dashboardSidebar(
sidebarMenu(
# Setting id makes input$tabs give the tabName of currently-selected tab
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"),
sliderInput("slider", "Slider Input", min = 0, max = 10, step = 1, value = 5))
)
)
body <- dashboardBody(
tabItems(
tabItem("dashboard", textOutput("Dashboard"))
)
)
ui <- dashboardPage(
dashboardHeader(),
sidebar,
body)
server <- function(input, output, session) {
output$Dashboard <- renderText({
paste("You've selected:", input$slider)
})
}
shinyApp(ui, server)
Ideally, I should see the number selected but that does not happen, unable to figure out where I am going wrong.
Upvotes: 1
Views: 813
Reputation: 84519
It looks like there's a problem when there is an input inside a menuItem
. You can do:
sidebar <- dashboardSidebar(
sidebarMenu(
id="tabs",
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
conditionalPanel(
"input.tabs == 'dashboard'",
sliderInput("slider", "Slider Input",
min = 0, max = 10, step = 1, value = 5))
)
)
Upvotes: 2
Reputation: 1233
Below is the code which works.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"),
sliderInput("slider", "Slider Input", min = 0, max = 10, step = 1, value = 5))
)
),
dashboardBody(
textOutput("dashboard")
))
server <- function(input, output, session) {
output$dashboard <- renderText({
paste("You've selected:", input$slider)
})
}
shinyApp(ui, server)
Upvotes: 0