我试图使用treeInputs过滤一个框架,但我很难过滤后者时,检查只有孩子框。你能帮助我实现这一点,请?下面的一个例子:
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(DT)
df <- data.frame(Parent=c("A", "A", "A", "B", "B"),
Child = c("1", "2", "3", "1", "2"),
Name = c("John", "Martin", "Emma", "Charlotte", "Olivia"))
ui <- dashboardPage(
dashboardHeader(title = "Title"),
dashboardSidebar(
# tree filter
treeInput("filter", "Myfilter", choices = create_tree(df[,c("Parent","Child")]))
),
dashboardBody(
# datatable
dataTableOutput("table")
)
)
# Serveur
server <- function(input, output) {
filtered_data <- reactive({
filtered <- df
# filtering for parent boxes
filtered <- filtered[filtered$Parent %in% sapply(input$filter, function(x) x[1]), ]
# filtering for children boxes
#### struggling here
return(filtered)
})
output$table <- renderDataTable({
datatable(filtered_data(), options = list(pageLength = 10))
})
}
shinyApp(ui, server)
字符串
1条答案
按热度按时间rslzwgfq1#
我们的想法是从
treeInput
返回ids
(而不是模糊的标签)。然后,我们需要做的“所有”就是在树id和原始 Dataframe 的行之间创建一个Map。这并不是非常简单,但是我们可以使用
library(data.tree)
来减少树遍历的痛苦。字符串