gpt4 book ai didi

shiny - R ShinyDashboard 文本输出到标题

转载 作者:行者123 更新时间:2023-12-02 03:45:25 26 4
gpt4 key购买 nike

我正在尝试在标题上获取自定义字段,以便人们知道上次刷新数据的时间。

在我的测试运行中,当我在代码中放入变量时,它就可以工作,但是当我使用 textOutput 时,它会为我提供 HTML 后台逻辑。

<div id="Refresh" class="shiny-text-output"></div>

下面是我的代码:

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)

这是我目前看到的:

enter image description here

已编辑以显示更正的代码

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)

最佳答案

您必须将内容以 HTML 形式粘贴到 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)

关于shiny - R ShinyDashboard 文本输出到标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46961737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com