Issue in Slider input range. Reason being the input values are not cumulative

I have a dataframe df . The requirement is once I select the input range from the slider and then click on update the table should be updated, There are 2 sliders and 2 actions button. For example if select input ranges for MOnday and click Mon_Update the table should get updated(No matter what input values are there for Tuesday) SImilarly if I select Input values for Tuesday and select Tue_Update the table should be updated

            library(shiny)
            library(ggplot2)

                   df <- structure(list(Col = 1:11, Mon = c(47L, 110L, 31L, 72L, 129L,
                                     41L, 85L, 123L, 14L, 152L, 118L), Tue 
                 = c(164L, 168L, 146L, 140L,
                     
                     185L, 77L, 26L, 15L, 23L, 116L, 101L), Wed = c(163L, 5L, 109L,
                                                                    
                                                                    170L, 37L, 96L, 41L, 188L, 163L, 82L, 5L), Area = structure(c(1L,
                                                                                                                                  
                                                                                                                                  1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L), .Label = c("A", "B",
                                                                                                                                                                                      
                                                                                                                                                                                      "C", "D"), class = "factor"), Street = structure(c(1L, 1L, 1L,
                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                         1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), .Label = c("Ste 1", "Ste 2"), 
                                                                                                                                                                                                                                       class =
                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                         "factor")), class = "data.frame", row.names = c(NA,
                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                         -11L))
                 ui <- fluidPage(
           tabsetPanel(tabPanel("Week",titlePanel(h4("Trend of
                                        Consumption",align="center")),
                   sidebarLayout(
                     sidebarPanel(selectInput("plot","plot",choices = 
                                                c("","display")),
                                  sliderInput("range", label = h6("Mon"), 
                                              min= min(df$Mon),max = max(df$Mon),
                                              value = c(min(df$Mon),  
                                                        max(df$Mon))),
                                  actionButton('clickme', label = 
                                                 h6("Mon_Update")),
                                  sliderInput("range1", label = h6("Tue"), 
                                              min= min(df$Tue),max = max(df$Tue),
                                              value = c(min(df$Tue),  
                                                        max(df$Tue))),
                                  actionButton('clickme1', label = 
                                                 h6("Tue_Update")),
                                  uiOutput("area"),uiOutput("street"),width = 2),
                     mainPanel(plotOutput("graph"),
                               dataTableOutput("graph1")
                     )
                   )
           ))
             )

               server <- function(input, output, session) {
               selectedData <- eventReactive(input$clickme,{
                  df[ df$Mon <= input$range, ]
         })
         graph1 <- reactive({
       if (input$plot == "display") {
       selectedData()
       }
           })
         output$graph1 <- renderDataTable(
{
  graph1()
}
        )
         selectedData1 <- eventReactive(input$clickme1,{
    df[ df$Tue <= input$range1, ]
           })
         graph1 <- reactive({
      if (input$plot == "display") {
  selectedData()
}
          })
         output$graph1 <- renderDataTable(
{
  graph1()
}
      )
    }

      shinyApp(ui, server)

The reason it is like that is because input$range returns a single value (e.g. 152), so when you say %in% basically you are filtering from a list of one.

Wouldn't it work by just amending the selection in this reactive:

selectedData <- reactive({
  df[ df$Mon %in% input$range, ]
         
      })

to

selectedData <- reactive({
  df[ df$Mon <= input$range, ]
         
      })
2 Likes

Thanks I am facing few challenges and sorry I did not know this would occur. I have edited my question for you. Now I have 2 sliders and 2 buttons corresponding to each day. When I select input values for MOnday and click Mon button the table should get reflected(Irrespective of values under Tuesday). When I select input values for Tuesday and click Tue button the table should get reflected(Irrespective of values for Monday)

The above looks peculiar - sliderInput returns a single value, so you should set the value parameter as a single value (scalar), not a vector.

1 Like

Hi I have changed now. But other slider and button is not working

You are beginning to abuse the kindness of the people this forum —it's fine to ask a few questions about an area that you are stuck on, but you appear to need considerably more help than you should expect to get for free. I'd recommend finding a Shiny consultant to help you out.

2 Likes

Appreciate your feedback But I face lots of challenges while coding