I am new to R shiny and having a struggle with it.
I have data set called 'performance' similar to below.
Date A B
2020-08-01 50 100
2020-08-03 50.95 34.9695
2020-08-03 54 1.39927
2020-09-01 150 350
2020-09-05 96.03 129.96
2020-09-07 68.41 35.9961
2020-10-01 75 200
2020-10-05 72.41 67.125
2020-11-01 35 250
I want to make reactive for date and A column If user select 2020-08-01~2020-08-03 in 'dateRangeInput' and type in 50 in 'numericinput' section then I want output of table should look like as below.
Date A B
2020-08-01 50 100
2020-08-03 50.95 34.9695
Here is the code I got so far. I am not sure whether how to make two different reactive in R shiny
library(shiny)
ui <- fluidPage(
title = "Performance Table",
dateRangeInput("daterange", "choose date",
start = min(performance$Date),
end = max(performance$Date),
min = min(performance$Date),
max = max(performance$Date),
format = "yyyy/mm/dd",
seperator="-"),
numericInput("num", "A", value = 0, min=0, max=500),
sidebarLayout(
sidebarPanel(
conditionalPanel(
'input.dataset === "performance"',
checkboxGroupInput("show_vars", "Columns in performance:",
names(performance), selected = names(performance))
),
mainPanel(
tabsetPanel(
id = 'dataset',
tabPanel("performance", DT::dataTableOutput("mytable1")),
)
)
)
)
server <- function(input, output) {
filteredData <- reactive({
req(input$daterange)
df <- performance[performance$Date >= input$daterange[1] &
performance$Date <= input$daterange[2] &
performance$A == trunc(input$num), ]
df[sample(nrow(df), 1000, replace = T), ]
})
output$data <- renderTable({
performance[, c("performance", input$show_vars), drop=FALSE]
}, rownames=TRUE)
output$mytable1 <- DT::renderDataTable({
DT::datatable(filteredData()[, input$show_vars, drop = FALSE])
})
}
shinyApp(ui, server)
when I run above code and select date 2020-08-01~2020-08-03 and type 50 in numericinput then I get output as below which is different to what I expect for the output. Is there a way that I can see the decimal values as well?
Date A B
2020-08-01 50 100