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.
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))
)
)
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)
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.