Skip to content

Need help to fix the max date filter problem in the date input

6 messages · Greg Minshall, Biplab Nayak, Jeff Newmiller +1 more

#
Biplab,

i'm not sure how to help you here, but this list pretty much runs on
plain ASCII (or, these days, utf-8) e-mail.  for the most part, without
attachments.  so, simply-formatted text, including code, with some
mechanism in the code to initialize any data structures (data frames,
matrices, etc.) needed for the example.

some of this is described in the posting guide
----
https://www.r-project.org/posting-guide.html
----

formatting your e-mail in this way will likely increase your odds of a
helpful reply.

cheers, Greg
#
Hi Greg,

Please find the R Code in the word file attached here. Its plain text format

Thanks & Regards
Biplab Nayak
On Wed, Jun 9, 2021 at 12:15 AM Greg Minshall <minshall at umich.edu> wrote:

            
#
Hi Greg,

Please find the objective of the code(bold) and code mentioned below. I was
trying to do to achieve the below objective but somehow it's not working.

1.Order assessment based on the latest due date so select input automatically
shows the order of assessment name.

2.Filter based on the one name or multiple names in the  select input



library(tidyverse)

#library(stringr)    # attached with tidyverse

#library(readr)

library(shiny)

library(dplyr)



ttclasses <- read_csv("~/tmp/ttclasses.csv")



#Filter data

ttclasses <-ttclasses %>%

   filter(str_detect(assessment, "Assignment"))

 *ttclasses <-ttclasses %>%  filter(str_detect(name, "Name"))*



##Remove NA values.

ttclasses <-ttclasses %>% drop_na("score")



*## Sort  assessment based on max due_date*

 *ttclasses  <- ttclasses [order( - due_date, assessment ),]*



#Convert to factor

ttclasses$assessment <- factor(ttclasses$assessment)



# please see the formats in help("strptime")

ttclasses$due_date <-  as.Date(ttclasses$due_date, format = "%m/%d/%y")

*ttclasses$name <- factor(ttclasses$name)*





# Define UI ----

ui <- fluidPage(



   # App title ----

   titlePanel("Assessment Dashboard"),



   # Sidebar layout with input and output definitions ----

   sidebarLayout(



     # Sidebar panel for inputs ----

     sidebarPanel(



       # Input: Selector for variable to plot the grades for the selected

       # assignment ----



         selectInput("assessment", "Assessment:",

                     c("Assignment 1" = "Assignment 1",

                       "Assignment 2" = "Assignment 2",

                       "Assignment 3" = "Assignment 3",

                       "Assignment 4" = "Assignment 4",

                       "Assignment 5" = "Assignment 5")),

       selectInput("name", "Name:",

                   ttclasses[,2]),



       dateRangeInput("due_date",

                      "Due-Date:",start = max(ttclasses$due_date) ,

                      separator = " - ")

     ),



     # Main panel for displaying outputs ----

     mainPanel(



       # Output: Plot of the requested variable against grade ----

       plotOutput("gradePlot")



     )

   )

)



# Define server logic to plot  ----

server <- function(input, output) {

   output$gradePlot <- renderPlot({

     grade_ad = input$assessment

     boxplot(ttclasses$score[ttclasses$assessment==grade_ad],

             frame.plot=FALSE, horizontal=TRUE, col="magenta",

main=grade_ad)

     ttclasses <-ttclasses %>%

       filter(ttclasses$due_date >= input$due_date[1] & ttclasses$due_date

              <= input$due_date[2])

   })

}



# Create Shiny app ----

shinyApp(ui, server)


Thanks & Regards
Biplab Nayak
On Wed, Jun 9, 2021 at 12:15 AM Greg Minshall <minshall at umich.edu> wrote:

            

  
  
#
Hi Greg,

Please find the objective of the code(bold) and code mentioned below. I was
trying to do to achieve the below objective but somehow it's not working.

1.Order assessment based on the latest due date so select input
automatically shows the order of assessment name.

2.Filter based on the one name or multiple names in the  select input



library(tidyverse)

#library(stringr)    # attached with tidyverse

#library(readr)

library(shiny)

library(dplyr)



ttclasses <- read_csv("~/tmp/ttclasses.csv")



#Filter data

ttclasses <-ttclasses %>%

   filter(str_detect(assessment, "Assignment"))

 ttclasses <-ttclasses %>%  filter(str_detect(name, "Name"))



##Remove NA values.

ttclasses <-ttclasses %>% drop_na("score")



*## Sort  assessment based on max due_date*

 ttclasses  <- ttclasses [order( - due_date, assessment ),]



#Convert to factor

ttclasses$assessment <- factor(ttclasses$assessment)



# please see the formats in help("strptime")

ttclasses$due_date <-  as.Date(ttclasses$due_date, format = "%m/%d/%y")

ttclasses$name <- factor(ttclasses$name)

Thanks & Regards
Biplab Nayak
On Wed, Jun 9, 2021 at 12:15 AM Greg Minshall <minshall at umich.edu> wrote:

            

  
  
#
You seem to need to educate yourself as to what "plain text" means, and to read the Posting Guide for this mailing list. Word documents are very definitely NOT plain text. Stop attempting to communicate via formatted text on this mailing list.

For security reasons this mailing list removes most attachments and formatting. Your emails sent to the list have such features (e.g Word documents and HTML formatting) stripped (removed). If you happen to send such emails directly to specific people they might have software that can allow them to view that information if they choose to risk opening attachments from a stranger (I will not), but for those of us seeing your emails on the list "what you send is not what we receive". Such emails are repeatedly violating the Posting Guidelines which will make responses much less likely and may increase the chance of a negative moderator reaction.
On June 8, 2021 8:47:52 PM PDT, Biplab Nayak <biplabn1 at gmail.com> wrote:

  
    
#
On 6/9/21 5:06 AM, Biplab Nayak wrote:
The phrase "somehow not working" is not a useful description of an outcome.
I'm pretty sure the tidyverse super-package includes most of the others 
with the exception of pkg:shiny (which does not appear to be needed anyway.)

Here's what my version of tidyverse loads:

Imports: broom (>= 0.5.2), cli (>= 1.1.0), crayon (>= 1.3.4), dbplyr (>= 
1.4.2), dplyr (>= 0.8.3), forcats (>= 0.4.0),
 ???????????? ggplot2 (>= 3.2.1), haven (>= 2.2.0), hms (>= 0.5.2), httr 
(>= 1.4.1), jsonlite (>= 1.6), lubridate (>=
 ???????????? 1.7.4), magrittr (>= 1.5), modelr (>= 0.1.5), pillar (>= 
1.4.2), purrr (>= 0.3.3), readr (>= 1.3.1), readxl
 ???????????? (>= 1.3.1), reprex (>= 0.3.0), rlang (>= 0.4.1), 
rstudioapi (>= 0.10), rvest (>= 0.3.5), stringr (>=
 ???????????? 1.4.0), tibble (>= 2.1.3), tidyr (>= 1.0.0), xml2 (>= 1.2.2)
We do not have your data.
Without a result that summarizes the changes in the data composition at 
each step, we cannot make any guesses as to your problem
Yes, do see ?strptime. That format assumes dates are in MM/DD/YY format, 
i.e slashes as separators and 2 digit years. Getting the date format 
wrong is a common way to create NA values. It is better not to overlay 
such efforts on top of the original column name. That way you can still 
make changes without redoing the entire data steps.