Kev*_*vin 2 shiny shinydashboard
我试图在标题上获取一个自定义字段,以便人们知道上次刷新数据的时间。
在我的测试运行中,我只在代码中放置一个变量时就可以工作,但是当我使用textOutput它时,它给了我 HTML 背景逻辑。
<div id="Refresh" class="shiny-text-output"></div>
Run Code Online (Sandbox Code Playgroud)
下面是我的代码:
library (shiny)
library (shinydashboard)
rm(list=ls())
header <- dashboardHeader(
title = "TEST",
tags$li(class = "dropdown", tags$a(paste("Refreshed on ", textOutput("Refresh")))))
body <- dashboardBody(
fluidRow(box(textOutput("Refresh")))
)
sidebar <- dashboardSidebar()
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
output$Refresh <- renderText({
toString(as.Date("2017-5-4"))
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
这是我目前看到的:
编辑以显示更正的代码
library (shiny)
library (shinydashboard)
header <- dashboardHeader(
title = "TEST",
tags$li(class = "dropdown", tags$a((htmlOutput("Refresh1")))))
body <- dashboardBody(
fluidRow(box(textOutput("Refresh2")))
)
sidebar <- dashboardSidebar()
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
output$Refresh1 <- renderUI({
HTML(paste("Refreshed on ", toString(as.Date("2017-5-4"))))
})
output$Refresh2 <- renderText({
toString(as.Date("2017-5-4"))
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
您必须将内容粘贴为HTMLinside tags$a,如下所示。您还必须renderText两次,因为不能在 UI 中使用相同的值。
library (shiny)
library (shinydashboard)
rm(list=ls())
header <- dashboardHeader(
title = "TEST",
tags$li(class = "dropdown", tags$a(HTML(paste("Refreshed on ", textOutput("Refresh1"))))))
body <- dashboardBody(
fluidRow(box(textOutput("Refresh2")))
)
sidebar <- dashboardSidebar()
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
output$Refresh1 <- renderText({
toString(as.Date("2017-5-4"))
})
output$Refresh2 <- renderText({
toString(as.Date("2017-5-4"))
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)