【问题标题】:R - Dashboard date in a shiny app deployed in shinyapps.ioR - 在 shinyapps.io 中部署的闪亮应用程序中的仪表板日期
【发布时间】:2020-08-29 01:31:44
【问题描述】:

我在 Shiny 中创建了一个仪表板,每周有 3 次新数据,因此我尝试使用命令“today()" 在我发布它时,但是当有人在 shinyapps.io 中重新加载仪表板时,更新日期将更改为当前日期。

有没有什么方法可以在我发布时确定日期,而无需手动写下来?

这是我的代码:

hcmap("countries/co/co-all", showInLegend = FALSE) %>%
hc_credits(enabled = TRUE,
           text = str_c("Data Source: www.---.com.<br/> Update Date:", format(today(), format="%d/%B/%Y"), sep = " "),
           style = list(fontSize = "11px"), position = list(align = "center",y = -35))

【问题讨论】:

    标签: r date shiny shinydashboard


    【解决方案1】:

    我不确定您是否已经得到解决方案。这是我最近使用的。

    您可以在 UI 中使用数据的修改日期。在全球。 R,使用以下命令获取数据的修改日期:

    updateDate &lt;- format(file.info("file path")$mtime, "%Y-%m-%d")

    然后使用updateDate 而不是today()

    【讨论】:

    • 谢谢!更新日期运行得非常好!
    【解决方案2】:

    闪亮的时间在服务器上是流动的,在外面是陈旧的

    library(shiny)
    library(lubridate)
    this_is_fixed <- now()
    
    ui <- fluidPage(
    
      # App title ----
      titlePanel("Time in the shiny world"),
    
      mainPanel(
          verbatimTextOutput(outputId = "fixed"),
          verbatimTextOutput(outputId = "fluid")
    
        )
      )
    
    
    # Define server logic required to draw a histogram ----
    server <- function(input, output) {
    
      output$fixed <- renderText({
        this_is_fixed
      })
    
      output$fluid <- renderText({
        now()
      })
    
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 我已经尝试过了,但问题仍然存在:每次用户重新加载仪表板时,日期都会发生变化。 #Outside ui 和 server fixed % hc_credits( enabled = TRUE, text = str_c("数据来源: www.---.com.
      更新日期:", fixed, sep = " "), style = list(fontSize = "11px"), position = list(align = "center",y = -35))
    猜你喜欢
    • 2018-02-03
    • 2017-09-05
    • 2019-04-24
    • 1970-01-01
    • 2015-11-13
    • 2015-04-22
    • 2019-03-19
    • 2018-08-31
    • 2014-07-31
    相关资源
    最近更新 更多