Hi, I'm new to Shiny and noticed something that prevents my typical coding practice (which is maybe bad?).
Something like this will give an error:
years_server <- function(id, .data){
moduleServer( id, function(input, output, session){
.data <- reactive({
.data |>
dplyr::filter(year %in% input$year[1]:input$year[2])
})
output$table <- renderTable(.data())
})
})
But when writing a general R function, this is fine:
summarize_years <- function(.data){
.data <- .data |>
dplyr::arrange(year)
.data
}
Why is that?
Reprex below:
library(shiny)
ui <- fluidPage(
mainPanel(
tableOutput("table")
),
sliderInput(
inputId = "mpg",
label = "Choose mpg",
step = 1,
sep = "",
min = 15,
max = 20,
value = c(15, 20)
)
)
mpg_server <- function(id, .data){
moduleServer( id, function(input, output, session){
.data <- reactive({
.data |>
dplyr::filter(mpg %in% input$mpg)
})
output$table <- renderTable(.data())
})
}
server <- function(input, output, session, .data) {
.data <- mpg_server("test", .data = mpg)
output$table <- renderTable(.data())
}
shinyApp(ui = ui, server)