[英]Output not displayed i shiny app using shinydashboard
I have a sliderInput
in a menuItem
which can be moved and the selected number needs to be displayed on the screen. 我在menuItem
有一个sliderInput
,可以移动它,并且需要在屏幕上显示所选的数字。 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
. 当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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.