Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny showing numbers instead of dates

Tags:

date

r

shiny

I'm trying to show a table with Shiny, but I have a problem showing dates in the right format. Here is an example of what I'm dealing with:

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)
like image 311
Bram Avatar asked Nov 23 '25 02:11

Bram


2 Answers

This works as well :)

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

Enjoy and Keep Posting!

like image 113
Ashish Baid Avatar answered Nov 24 '25 18:11

Ashish Baid


It seems to work if you change the line:

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

to:

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

like image 35
mrhellmann Avatar answered Nov 24 '25 17:11

mrhellmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!