David Bijoyan
David Bijoyan

Reputation: 117

How to specify menuItem in ShinyDashboard?

I'm creating Shiny web app using shinydashboard package version 0.7.1.

So I faced a problem that nothing happens when I specify 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.

Any ideas gow can I handle this problem?

Thanks.

Upvotes: 0

Views: 1817

Answers (1)

Kevin
Kevin

Reputation: 2044

Few things that needed to change...

  1. You have an extra sidebarMenu() that was unnecessary
  2. You need the icon("x") to be 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)

Upvotes: 1

Related Questions