1

To add text to my dashboard header I adopted the solution of the second answer to this question (with styles.css file). I have to insert dynamic text while the script only allows static text. My text is:

format(Sys.Date(), format="%A  %d %b %Y")

how to solve?

stefanodv
  • 463
  • 3
  • 11
  • 20
  • When in the linked solution by Tiffany do you want your custom text inserted? Part of `tags$script`? `tags$head`? or `styles.css`? – Simon.S.A. Oct 08 '18 at 00:23

1 Answers1

0

Below are the two different solutions if you want to display dynamic dates on header in Shiny.

This code will be helpful if you need to use shinydashboard package

library(shiny)
library(shinydashboard)

header <- dashboardHeader(
  title = "dynamicDates",
  tags$li(class = "dropdown", tags$a(HTML(paste(uiOutput("Refresh1"))))))
body <- dashboardBody()
sidebar <- dashboardSidebar()

ui <- dashboardPage(header, sidebar, body)

server <- function(input, output) {
  output$Refresh1 <- renderText({
    toString(format(Sys.Date(), format = "%A  %d %b %Y"))
  })
}
shinyApp(ui, server)

In this code i'm not using shinydashboard package. With plain shiny functions in combination of few HTML tags we can customize as per need.

library(shiny)
ui <- fluidPage( 
  titlePanel("", windowTitle = "Dynamic Dates"),
  titlePanel(title = tags$div(img(src = "https://www.rstudio.com/wp-content/uploads/2014/04/shiny.png", width = 125, height = 115, align = "left"))),
  titlePanel(title = tags$div(class = "header" , tags$p("Dynamic", tags$b(" Dates"),style = "text-align: center; color:navy;"), style = "text-align: center; color:navy;")),
  titlePanel(title = tags$div(uiOutput("dynamicDate"), align = 'right')))

server <- function(input, output) {
  output$dynamicDate <- renderUI(toString(format(Sys.Date(), format = "%A  %d %b %Y")))
  }
shinyApp(ui, server)
msr_003
  • 1,205
  • 2
  • 10
  • 25