Search code examples
rshinyshiny-servershinydashboard

How to read & display time in Navbar of Shiny R Dashboard


I want to display Last Updated time in the navbar of shiny R. For that I'm storing the last updated time in csv file which I will be using to read in the server.R but I'm unable to figure out how to display that time on the rightmost side of the navbar. Any help would be highly appreciated. Thank You

    shinyUI(
       navbarPage(
              title = 'Welcome',
               tabPanel('Overview',
           tabsetPanel(
           tabPanel('Forward',
                    fluidRow(
                      DT::dataTableOutput("view_fwd"),width = 6
                    )
           ),
           tabPanel('Reverse',
                    fluidRow(
                      DT::dataTableOutput("view_rvo"),width = 6
                    ))

           ))

Solution

  • library(shiny)
    
    
    ui <- fluidPage(
    
      navbarPage(
        title = 'Welcome',
        tabPanel('Overview',
                 tabsetPanel(
                   tabPanel('Forward',
                            fluidRow(
                              DT::dataTableOutput("view_fwd"),width = 6
                            )
                   ),
                   tabPanel('Reverse',
                            fluidRow(
                              DT::dataTableOutput("view_rvo"),width = 6
                            ))
    
                 )),
                  tabPanel(tags$ul(class='nav navbar-nav', 
                                   style = "padding-left: 550px;", htmlOutput("time"))) # here you output time, need to positions on the left side by 550px
        )
    
    )
    
    # Define server logic
    server <- function(input, output) {
    
      output$time <- renderUI({
    
        as.character(strptime(Sys.time(), "%Y-%m-%d %H:%M:%S", tz = "EET"))
    
    
      })
    
    }
    
    # Run the application 
    shinyApp(ui = ui, server = server)