我在sliderInput
中有一个menuItem
,可以移动它,并且需要在屏幕上显示所选的号码。下面是代码:
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)
理想情况下,我应该看到选择的号码,但那不会发生,无法弄清楚我要去哪里。
答案 0 :(得分:2)
在menuItem
中有输入时,似乎有问题。您可以这样做:
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))
)
)
答案 1 :(得分:0)
下面是有效的代码。
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)