首页 > 解决方案 > 闪亮的显示数字而不是日期

问题描述

我正在尝试用 Shiny 显示一个表格,但是我在以正确的格式显示日期时遇到了问题。这是我正在处理的一个例子:

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(
  sidebarLayout(

    sidebarPanel(
      textInput("myfirstinput", "text1"),
      textInput("mysecondinput", "text2"),
      actionButton("button", "An action button")
    ),
    mainPanel(
      tableOutput("table1")
    )
  )
)


# Define server logic required to draw a histogram
server <- function(input, output) {
  selected <- as.Date('2000-01-01', "%Y-%m-%d")
  selected <- as.list(selected)

  output$table1 <- renderTable(selected)

}

# Run the application 
shinyApp(ui = ui, server = server)

标签: rdateshiny

解决方案


如果您更改线路,它似乎有效:

  selected <- as.Date('2000-01-01', "%Y-%m-%d")

到:

    selected <- format(as.Date('2000-01-01'), "%Y-%m-%d")


推荐阅读