Home > database >  Create a text output based on if conditions are met or not
Create a text output based on if conditions are met or not

Time:10-01

I am not a coder, but I'm forced to code during an internship and could really need some help.
I am adapting already existing code and need to display a sentence on a dashboard if and only if old data is used for the output. I was looking through Stack Overflow and thought that I should go with the conditional panel.

In the UI we are using radioButtons to select a month:

column(12,
       radioButtons("radio", h4(paste("Results:")),
       choices = list( "Jan" = paste(year(Sys.Date()-30), '-01-31', sep=""), 
                       "Feb" = paste(year(Sys.Date()-30), '-02-28', sep=""),
                       "Mar" = paste(year(Sys.Date()-30), '-03-31', sep=""), 
                       "Apr" = paste(year(Sys.Date()-30), '-04-30', sep=""),
                       "Mai" = paste(year(Sys.Date()-30), '-05-31', sep=""),
                       "Jun" = paste(year(Sys.Date()-30), '-06-30', sep="")
                       "Jul" = paste(year(Sys.Date()-30), '-07-31', sep=""), 
                       "Aug" = paste(year(Sys.Date()-30), '-08-31', sep=""),
                       "Sep" = paste(year(Sys.Date()-30), '-09-30', sep=""),
                       "Oct" = paste(year(Sys.Date()-30), '-10-31', sep=""),
                       "Nov" = paste(year(Sys.Date()-30), '-11-30', sep=""),
                       "Dec" = paste(year(Sys.Date()-30), '-12-31', sep="")),
                      
       selected = format(c(as.Date(d)-1),"%Y-%m-%d"), inline =TRUE)))

If I select a month on the radio buttons, for which we do not have the data yet, I display the latest information we have. But I would also like to indicate this in a sentence above the plots.

So in the server, I tried this:

output$is_old_data <- renderText(
    if(max(dshb_qt_2$Data) < input$radio){
      1
    }else{
      0
    }
  )

And in the UI, I wanted to display it by this:

fluidRow(
          conditionalPanel("is_old_data == 1", "Old data was used")
         )

Unfortunately, it is now displaying "Old data was used" no matter if it is actually old data or not. The if/else part does work. I know that because I have already used it for other parts. Does someone know what do here?

CodePudding user response:

Try this:

output$is_old_data <- reactive(
    if(max(dshb_qt_2$Data) < input$radio){
      1
    }else{
      0
    }
  )
outputOptions(output, "is_old_data", suspendWhenHidden = FALSE)

and in UI:

conditionalPanel(
  "output.is_old_data == 1",
  ......
  • Related