r - 如何将日期从服务器传递到 ui,以便我可以在 airDatepickerInput 中使用它
问题描述
我闪亮的服务器上有一个带有日期的数据集。我创建了一个获取最大日期的变量,我需要将它传递给 UI,以便我可以将其用作日历的最大限制。我对此有疑问。df 在 server.R 文件的服务器部分之外
服务器
server <- function(input, output, session) {
date_max = max(as.Date(df.direccionamientos$D_FecDireccionamiento))
output$date_max = reactive ({ format (date_max, "%Y-%m-%d") })
outputOptions(output, 'date_max', suspendWhenHidden = FALSE)
}
用户界面
ui <- fluidPage(
tags$head(
HTML("<title>Mipres</title>"),
HTML(".shiny-notification {
position:fixed;
top: calc(0%);
left: calc(90%);
}
"
)
),
),
img(src = "saludmia-s.png", height = 110, width = 250),
titlePanel(
h1("Informes MIPRES", align = "center")),
hr(style = "border-top: 1px solid #000000;"),
fluidRow(
column(2,
titlePanel(h3("Parametros de busqueda")),
titlePanel(h4("Fecha")),
textOutput("date_max"),
condition = as.Date("output.date_max"),
airDatepickerInput(
inputId = "date2",
#label = "Select range of dates:",
range = F,
autoClose = T,
value = Sys.Date()+1 ,
# Sys.Date()),
todayButton = F,
clearButton = T,
maxDate = condition ,
addon = c("none")
),
),
#Table Showing Processed Data
# tableOutput("mytable"),
)
解决方案
一种方法是使用在服务器端renderUI
显示airDatepickerInput()
。然后你可以在date_max
那里使用。尝试这个
ui <- fluidPage(
tags$head(
HTML("<title>Mipres</title>"),
HTML(".shiny-notification {
position:fixed;
top: calc(0%);
left: calc(90%);
}
"
)
),
img(src = "saludmia-s.png", height = 110, width = 250),
titlePanel(
h1("Informes MIPRES", align = "center")),
hr(style = "border-top: 1px solid #000000;"),
fluidRow(
column(2,
titlePanel(h3("Parametros de busqueda")),
titlePanel(h4("Fecha")),
textOutput("date_max"),
#condition = as.Date("output.date_max"),
uiOutput("airdatepicker")
))
)
server <- function(input, output, session) {
date_max = max(as.Date(df.direccionamientos$D_FecDireccionamiento))
output$airdatepicker <- renderUI({
airDatepickerInput(
inputId = "date2",
#label = "Select range of dates:",
range = F,
autoClose = T,
value = Sys.Date()+1 ,
# Sys.Date()),
todayButton = F,
clearButton = T,
maxDate = date_max ,
addon = c("none")
)
})
output$date_max = reactive ({ format (date_max, "%Y-%m-%d") })
outputOptions(output, 'date_max', suspendWhenHidden = FALSE)
}
shinyApp(ui, server)
推荐阅读
- iis - IIS7 - 重写公用文件夹中的文件和子目录
- stata - 如何将一个变量的内容替换为另一个变量的内容?
- node.js - 使用带有 NestJS 的 aws 加密库的“EC2 元数据角色名称请求返回错误”
- flutter - Flutter:如何创建并公开图片到公共下载文件夹?
- sql - SQL Group By 不同列上的多个值
- javascript - 如何仅旋转 div 内的内容?
- .net - foreach Azure.Pageable
然后抛出 System.FormatException - python - 使用 FORMDATA 的 scrapy 问题使用凭据抓取网站
- angular - 如何在单元测试中将事件对象传递给 triggerEventHandler?
- python - 如何使用 python 从目录中检测和分离损坏/不可读的 PDF 和受密码保护的 PDF?