I'm creating a simple shiny app using the {golem} package. Below is the code I've used for my first module:
@importFrom shiny NS tagList
mod_plot_module_ui <- function(id){
ns <- NS(id)
tagList(
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "life", label = "Life expectancy",
min = 0, max = 120,
value = c(30, 50)),
selectInput("continent", "Continent",
choices = c("All", levels(gapminder$continent))),
downloadButton("download_data")
),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput(ns("plot"))),
tabPanel("Table", DT::renderDataTable(ns("table")))
)
)
)
)
}
plot_module Server Function
@noRd
mod_plot_module_server <- function(input, output, session){
ns <- session$ns
filtered_data <- reactive({
data <- gapminder
data <- data[data$lifeExp >= input$life[1] & data$lifeExp <= input$life[2]]
if (input$continent != "All") {
data <- data[continent == input$continent]
}
data
})
output$plot <- renderPlot({
data <- filtered_data()
ggplot(data, aes(gdpPercap, lifeExp)) +
geom_point() +
scale_x_log10()
})
}
However, when I run the application, I get this error message:
Listening on http://127.0.0.1:3775
Warning: Error in : Must subset columns with a valid subscript vector.
Logical subscripts must match the size of the indexed input.
x Input has size 6 but subscript data$lifeExp >= input$life[1] & data$lifeExp <= input$life[2]
has size 0.
203:
I don't understand what this error message means. Can someone help with this? Many thanks in advance.