【问题标题】:How to output the default date in dateInput()?如何在 dateInput() 中输出默认日期?
【发布时间】:2020-05-12 17:09:53
【问题描述】:

我想用 dateInput() 做同样的事情。我将如何输出 dateInput() 中设置的默认日期来表示 verbatimTextOutput()?

代码:

library(shiny)
library(shinythemes)

ui <- fluidPage(      
  theme = shinytheme('slate'),

  sidebarPanel(
    selectInput(
      'country',
      'Select a Country',
      c('Japan', 'China', 'USA'),
      selected = 'Japan'
    ),

    dateInput(
      'date',
      label = 'Select a Date',
      value = as.character(as.Date('05/10/20', '%m/%d/%y')),
      min = as.Date('01/22/20', '%m/%d/%y'),
      max = as.Date('05/10/20', '%m/%d/%y'),
      format = 'mm/dd/yy',
      startview = 'month',
      weekstart = 1
    ),

    actionButton('resetBtn', 'Reset'),

    actionButton('plotBtn', 'Plot', class = 'btn-primary')
  ),
  mainPanel(
    verbatimTextOutput('dateText', placeholder = TRUE)
  )
)

server <- function(input, output) {

  dateInput <- eventReactive(input$plotBtn, {
    input$date
  }, ignoreNULL = FALSE)

  output$dateText <- renderText({
    as.character(dateInput())
  })
}


shinyApp(ui, server)

上面的代码还是不行,我在网上也找不到和这个匹配的答案。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    使用renderPrint 代替renderText

    【讨论】:

      猜你喜欢
      • 2021-08-13
      • 2021-05-27
      • 2019-09-12
      • 1970-01-01
      • 1970-01-01
      • 2021-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多