Hello my friends,
I m new as i'm happy to have discovered shiny. I look for help as since wednesday i try to learn how to filter date and date from a database as it looks less intuitive than in R. Please see a basic code (inspired from others people) from which i learn.
- code
==
set.seed(123)
foo <- data.frame(
date = sample(seq(as.Date('2010-01-01'), as.Date('2023-01-01'), by = 'day'), 20),
var1 = sample(1:15, 20, replace = TRUE),
var2 = sample(16:30, 20, replace = TRUE)
) %>%
arrange(date)
user interface
ui <- fluidPage(
sliderInput('year', 'Year', min = 2010, max = 2023,
step =1, value = c(2018,2020), sep = ''),
selectizeInput('data', 'Variable',
choices = c("var1", "var2"), selected = "var1", multiple=FALSE),
dataTableOutput('table')
)
server <- function(input, output, session) {
dataset <- reactive({
foo %>%
filter(year(date) >= input$year[1], year(date) <= input$year[2])
})
output$table <- renderDataTable({
dataset()
})
}
Create Shiny app ----
shinyApp(ui, server)
==
2) 2 questions:
- i would like the table to display the filtered dates with the chosen variable, let's say var1.
- i would like to insert a plot/table to display e.g. the regression coefficients/R² of var2 on var1.
Many thanks for modifying the code to help me understand how manipulate Shiny.