I am currently trying to make an application that takes in a large data frame and then filters based on a column from the uploaded data frame, before displaying a table for the user. When I try to filter based on the value of the dependent input, I receive an error that the filter value must be ‘[size of the data frame] or 1, not size 0’. I can render the output of the value, just not filter with it.
I’m new to writing modules, so there may be something very obvious that I am missing, but I have not been able to work it out yet.
<code>
#Reprex modules
library(shiny)
library(bslib)
library(DT)
testUI<-function(id){
ns<-NS(id)
tagList(
layout_columns(selectInput(ns("carb"), "Carb", choices = seq(1:10), selected = 4),
uiOutput(ns("cyl"))),
tableOutput(ns("table")),
tableOutput(ns("table_ouput"))
# textOutput(ns("cyl_text"))
)
}
###initial filter function in UI to make dynamic dummy dataframe
fetchServer <- function(id) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
return(reactive(input$carb))
})
}
##the initial data frame where the filtering column is located
testServer <- function(id, .carb) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
data<-reactiveValues(data = NULL)
observe(data$data<-mtcars%>%filter(carb == .carb()))
output$table<-renderTable(data$data)
return(reactive(data$data))
})
}
##rendering the values from the filtering column in the module's UI
cylServer <- function(id, carb_data) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
output$cyl<-renderUI({
selectInput(
ns("cyl"),
"Cyl",
choices = carb_data()$cyl)
})
return(reactive(input$cyl))
})
}
##attempting to filter based on the user's selection of the rendered UI element
new_tableServer <- function(id, .cyl) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
data<-reactiveValues(data = NULL)
observe(data$data<-mtcars%>%filter(cyl == .cyl()))
output$table_output<-renderTable(data$data)
# output$cyl_text<-renderText(.cyl())
})
}
</code>
<code>
#Reprex modules
library(shiny)
library(bslib)
library(DT)
testUI<-function(id){
ns<-NS(id)
tagList(
layout_columns(selectInput(ns("carb"), "Carb", choices = seq(1:10), selected = 4),
uiOutput(ns("cyl"))),
tableOutput(ns("table")),
tableOutput(ns("table_ouput"))
# textOutput(ns("cyl_text"))
)
}
###initial filter function in UI to make dynamic dummy dataframe
fetchServer <- function(id) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
return(reactive(input$carb))
})
}
##the initial data frame where the filtering column is located
testServer <- function(id, .carb) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
data<-reactiveValues(data = NULL)
observe(data$data<-mtcars%>%filter(carb == .carb()))
output$table<-renderTable(data$data)
return(reactive(data$data))
})
}
##rendering the values from the filtering column in the module's UI
cylServer <- function(id, carb_data) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
output$cyl<-renderUI({
selectInput(
ns("cyl"),
"Cyl",
choices = carb_data()$cyl)
})
return(reactive(input$cyl))
})
}
##attempting to filter based on the user's selection of the rendered UI element
new_tableServer <- function(id, .cyl) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
data<-reactiveValues(data = NULL)
observe(data$data<-mtcars%>%filter(cyl == .cyl()))
output$table_output<-renderTable(data$data)
# output$cyl_text<-renderText(.cyl())
})
}
</code>
#Reprex modules
library(shiny)
library(bslib)
library(DT)
testUI<-function(id){
ns<-NS(id)
tagList(
layout_columns(selectInput(ns("carb"), "Carb", choices = seq(1:10), selected = 4),
uiOutput(ns("cyl"))),
tableOutput(ns("table")),
tableOutput(ns("table_ouput"))
# textOutput(ns("cyl_text"))
)
}
###initial filter function in UI to make dynamic dummy dataframe
fetchServer <- function(id) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
return(reactive(input$carb))
})
}
##the initial data frame where the filtering column is located
testServer <- function(id, .carb) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
data<-reactiveValues(data = NULL)
observe(data$data<-mtcars%>%filter(carb == .carb()))
output$table<-renderTable(data$data)
return(reactive(data$data))
})
}
##rendering the values from the filtering column in the module's UI
cylServer <- function(id, carb_data) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
output$cyl<-renderUI({
selectInput(
ns("cyl"),
"Cyl",
choices = carb_data()$cyl)
})
return(reactive(input$cyl))
})
}
##attempting to filter based on the user's selection of the rendered UI element
new_tableServer <- function(id, .cyl) {
moduleServer(id, function(input, output, session) {
ns<-session$ns
data<-reactiveValues(data = NULL)
observe(data$data<-mtcars%>%filter(cyl == .cyl()))
output$table_output<-renderTable(data$data)
# output$cyl_text<-renderText(.cyl())
})
}
<code>#Reprex App
ui <- page(
testUI("x1")
)
server <- function(input, output) {
carb<-fetchServer("x1")
data<-testServer("x1", carb)
cyl<-cylServer("x1", data)
new_tableServer("x1", cyl)
}
shinyApp(ui = ui, server = server)
</code>
<code>#Reprex App
ui <- page(
testUI("x1")
)
server <- function(input, output) {
carb<-fetchServer("x1")
data<-testServer("x1", carb)
cyl<-cylServer("x1", data)
new_tableServer("x1", cyl)
}
shinyApp(ui = ui, server = server)
</code>
#Reprex App
ui <- page(
testUI("x1")
)
server <- function(input, output) {
carb<-fetchServer("x1")
data<-testServer("x1", carb)
cyl<-cylServer("x1", data)
new_tableServer("x1", cyl)
}
shinyApp(ui = ui, server = server)