【发布时间】:2017-12-14 17:35:34
【问题描述】:
我想知道是否可以得到你的帮助。
背景:我正在构建一个闪亮的应用程序(参见此处:https://camh-nds.shinyapps.io/STOPDataQuality/)来帮助控制数据质量
问题 #1
在“SOR”选项卡中,第 1 步:目标是在 DateSurveyed = WorkshopDate 时通知用户,并在正确与否时显示相应的消息。这很好用。
对于第 2 步:有效的 QuitDate 介于此范围之间:
DateSurveyed>= QuitDate DateSurveyed + days(30)
如果满足此条件,则显示以下文本:“输入的退出日期有效。
如果条件不满足,我想显示更正后的退出日期。
- 正确的戒烟日期基于:
i) 如果QuitDate DateSurveyed,则显示以下文本:“正确的退出日期是[此处DateSurveyed的值]
ii) 如果QuitDate > DateSurveyed + days (30) 则显示以下文本:“正确的退出日期是 [DateSurveyed + days(30) 的值]。
这是用户界面代码
dashboardBody(
tabItems(
#Data Quality for Stop on The Road (SOR)
tabItem(tabName="SOR",
#Checking if Date Surveyed= Workshop Date
h3("Step 1- check to see if Date Surveyed = Workshop Date"),
HTML ('</br>'),
#Entering Date Surveyed
dateInput('date',
label='Date Surveyed: yyyy-mm-dd'),
#Entering Workshop Date
dateInput('date2',
label='Workshop Date: yyyy-mm-dd'),
#If DateSurveyed=WorkShopDate display this message
conditionalPanel("input.date==input.date2",
textOutput("EqualDates")),
#If DateSurveyed!=WorkshopDate display this message
conditionalPanel ("input.date!=input.date2",
textOutput("ErrorDates")),
HTML ('</br>'),
HTML ('</br>'),
HTML ('</br>'),
#Checking to see if a Valid Quit Date has been entered
h3("Step 2- check to see if subject has entered a valid quit date"),
#Description to user what is a Valid Quit date
h5("* Note: Quit Dates can start as early as Date Surveyed or be set on 30 days after the Date Surveyed"),
HTML ('</br>'),
#Entering Quit Dates
dateInput('date3',
label='Quit Date: yyyy-mm-dd'),
#Valid Quit Dates: if QuitDate>=DateSurveyed AND QuitDate<=DateSurveyed + days(30);
#Then display message
conditionalPanel("input.date3>=input.date && input.date3<=input.date + days(30)",
#HELP! Conditional statement is not working!!!
textOutput("ValidQuitDate")),
#Incorrect Quit Dates: if QuitDate<DateSurveyed OR QuitDate>DateSurveyed + days(30);
#Then display message
conditionalPanel("input.date3<input.date || input.date3>input.date + days(30)",
#HELP! Conditional statement is not working!!!
textOutput("InvalidQuitDate"))
),
服务器:
library(lubridate)
library(shiny)
library(shinydashboard)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
#SOR Date Surveyed
output$dateText <- renderText({
paste("input$date is", as.character(input$date))
})
#SOR Work Shop Date
output$dateText2 <- renderText({
paste("input$date2 is", as.character(input$date2))
})
#SOR: if DateSurveyed=WorkshopDate then display this message
output$EqualDates<- renderText({
"**CORRECT** Dates are Equal!!!"
})
#SOR: if DateSurveyed!= WorkshopDate then display this message
output$ErrorDates<- renderText({
"**ERROR** Dates are NOT Equal"
})
#SOR: if QuitDate=DateSurveyed OR QuitDate<= DateSurveyed+ days(30) then
display this message
output$ValidQuitDate<- renderText({
"You have entered a Valid Quit Date"
})
#SOR: if QuitDate<DateSurveyed OR QuitDate>DateSurveyed+ days(30) then
display this message
output$InvalidQuitDate<- renderText({
"**ERROR** Incorrect Quit Date Entered"
})
})
问题 2:计算年龄
在“年龄”选项卡中,我只想使用以下公式计算年龄: 年龄=(确定日期-出生日期)/365。例如,我想显示答案:19 岁零 3 个月(如果可能)。
这是我的 Github 仓库的链接:https://github.com/AhmadMobin/STOPDQ
感谢我能得到的帮助!
提前致谢
【问题讨论】: