I have a datatable that I construct using function1 and user input. I then want to use a cell value from this datatable as input to function2 to build another datatable. I am getting a filter error and think the issue is related to how I am selecting cell values. I am building of an existing SO solution here.
Assume we have iris data and function1 uses the user input to filter on species. The result of function1 is a result of a reactive call. Now function2 takes this result as input and uses the selected "cell" value (Sepal.Length) to further filter and build another datatable.
Thanks the comment by @Silentdevildoll, table2 is being constructed correctly (I think) but I still see this error:
Warning: Error in : Problem with filter()
input ..1
.
i Input ..1
is Sepal.Length == var
.
x Input ..1
must be of size 50 or 1, not size 0.
library(shiny)
library(DT)
ui <- fluidPage(
mainPanel(
fluidRow(
column(4, textInput('textInput1', label=NULL)),
column(1, actionButton('button1', label=NULL))
),
fluidRow(
column(8, DT::dataTableOutput("table1")),
column(4, DT::dataTableOutput("table2"))
)
)
)
server <- function(input, output, session){
data(iris)
function1 <- function(id){
return(dplyr::filter(iris, Species==id))
}
function2 <- function(df, var){
return(dplyr::filter(df, Sepal.Length==var))
}
data <- reactiveValues()
observeEvent(input$button1, { data$ID <- input$textInput1 })
table1_rec <- reactive({ function1(data$ID) })
output$table1 <- DT::renderDataTable({
req(data$ID)
DT::datatable(table1_rec(), selection = list(target = 'cell'))
})
table2_rec <- reactive({
selected = table1_rec()[input$table1_cells_selected]
function2(table1_rec(), selected)
})
output$table2 <- DT::renderDataTable({
DT::datatable(table2_rec())
})
}
shinyApp(ui, server)