简体   繁体   English

如何在 ShinyDashboard 中指定 menuItem?

[英]How to specify menuItem in ShinyDashboard?

I'm creating Shiny web app using shinydashboard package version 0.7.1.我正在使用shinydashboard包版本 0.7.1 创建 Shiny Web 应用程序。

So I faced a problem that nothing happens when I specify menuItem .所以我遇到了一个问题,当我指定menuItem时没有任何反应。

Here is the example:这是示例:

library(shinydashboard)
library(sqldf)
library(DBI)
library(foreign)
library(RPostgres)
library(stringr)
library(readxl)
library(ggplot2)
library(ggpubr)
library(formattable)
library(reshape2)

header <- dashboardHeader(title = "S-T")
sidebar <- dashboardSidebar(
    textInput("banc_lics", "No of license", value=1),
    dateInput("date_an", "Input date", value = "2019-02-01" ),
    sidebarMenu(
        sidebarMenu(
            menuItem("Credit Risk", tabName = "Credit Risk",  icon("abacus")),
            menuItem("Equity Risk", tabName = "Equity Risk", icon("wave-tiangle")))
        ),
    submitButton("Submit", icon("calculator"))
)

page <- dashboardBody(
    tabItems(
        tabItem(
            tabName = "Credit Risk", h1("Credit Risk"),
            fluidRow(
                box(width=12, title = "Таблица", tableOutput("data_table"))
            ),
            fluidRow(
                box(width=12, title = "График", plotOutput("data_plot"))
            ) 
        ),
        tabItem(tabName = "Equity Risk", h2("Equity Risk"))
    )
)

ui <-  dashboardPage(header, sidebar, page, skin="yellow")

server <- function(input, output) {}

shinyApp(ui = ui, server = server)

I don't see prespecified data_table and data_plot in the Body.我在data_plot中没有看到预先指定的data_tabledata_plot

Any ideas gow can I handle this problem?我可以处理这个问题吗?

Thanks.谢谢。

Few things that needed to change...需要改变的东西很少......

  1. You have an extra sidebarMenu() that was unnecessary你有一个额外的sidebarMenu()是不必要的
  2. You need the icon("x") to be icon = icon("x")您需要icon("x")icon = icon("x")

Full code:完整代码:

library(shinydashboard)

header <- dashboardHeader(title = "S-T")
sidebar <- dashboardSidebar(
  textInput("banc_lics", "No of license", value=1),
  dateInput("date_an", "Input date", value = "2019-02-01" ),
  sidebarMenu(
        menuItem("Credit Risk", tabName = "CR",  icon = icon("abacus")),
        menuItem("Equity Risk", tabName = "ER", icon = icon("wave-tiangle"))
      ),
  submitButton("Submit", icon("calculator"))
)

body <- dashboardBody(
  tabItems(
    tabItem(tabName = "CR", 
            h1("Credit Risk"),
            fluidRow(
              box(width=12, title = "Таблица", tableOutput("data_table"))
            ),
            fluidRow(
              box(width=12, title = "График", plotOutput("data_plot"))
            )
            ),
    tabItem(tabName = "ER", 
            h2("Equity Risk")
            )
  )
)

ui <-  dashboardPage(header, sidebar, body, skin="yellow")

server <- function(input, output) {}

shinyApp(ui = ui, server = server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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