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)