Difficulties in displaying value in shiny dashboard header

Hi, I am trying to display total cases in shiny dashboard header along with the text, but while trying to do so, I am getting error. Also I need to display the total cases in center of the header.
Need to display: Total Cases: 540,565

shinyApp(
ui = navbarPage("Cancer Story",theme = shinytheme("slate"), collapsible = TRUE,selected = "Home",
tabPanel("Home"),
navbarMenu("USA",
tabPanel("Types", "Type contents..."),
tabPanel("Cases", "Cases contents..."),
tabPanel("Analysis", "Modelling contents..."),
tabPanel("Top Stories", "Top stories so far")),
navbarMenu("World",
tabPanel("Historical", "Historical contents...")),
tabPanel(""),
tabPanel(""),
tabPanel("Total Cases:"),
tabPanel(textOutput("vBox"))
),
server = function(input, output) {
output$vBox <- renderText({
sum(Cancer$cases)})
})

This works. Now what are you trying to do?


library(shiny)
library(shinythemes)

Cancer <- data.frame(cases = 10)

ui <- navbarPage("Cancer Story",
  theme = shinytheme("slate"), collapsible = TRUE, selected = "Home",
  tabPanel("Home"),
  navbarMenu(
    "USA",
    tabPanel("Types", "Type contents..."),
    tabPanel("Cases", "Cases contents..."),
    tabPanel("Analysis", "Modelling contents..."),
    tabPanel("Top Stories", "Top stories so far")
  ),
  navbarMenu(
    "World",
    tabPanel("Historical", "Historical contents...")
  ),
  tabPanel(""),
  tabPanel(""),
  tabPanel("Total Cases:"),
  tabPanel(textOutput("vBox"))
)

server <- function(input, output) {
  output$vBox <- renderText({
    sum(Cancer$cases)
  })
}

shinyApp(ui, server)

I used two empty tabpanels before the tabpanel "Total Cases" in order to center it and also I displayed the cases (vBox) in the subsequent tabpanel. Question here is:

  1. how could I NOT use the 2 empty tabpanels and center the tabpanel containing text "Total Cases",
  2. how could I combine both "Total Cases with vBox" in the same.
  1. Actually that an easy way to centre the text. Otherwise maybe there's an align = "center" option. Or you might have to use CSS but then it gets nasty. https://stackoverflow.com/questions/36213587/r-shiny-center-tabsetpanel-labels

  2. Just paste the strings together

output$vBox <- renderText({
   paste("Total Cases:", sum(Cancer$cases))
 })
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.