我正在尝试使用类似于下图的日期创建分支复选框输入。
最终选择将是来自先前选择的名称的独特观察。每个名称可能有很多观察结果,所以我希望能够使用日期来选择特定的。下面是我当前代码的一个示例。我可以根据名称更新复选框输入以显示所有名称的观察结果。
用户界面
library(shiny)
library(dplyr)
shinyUI(
fluidPage(
navbarPage(inverse = TRUE,
tabPanel("Page Title",
sidebarPanel(width = 4,
selectizeInput("Name",
label = "Name",
choices = sort(unique(mydata$Name))
),
checkboxGroupInput("Observation",
label = "Observation",
choices = sort(unique(mydata$Observation))
)
)
,
mainPanel(
tableOutput("RepDimTable")
))
)))
服务器.r
library(shiny)
library(dplyr)
shinyServer(function(input, output, session){
dat <- reactive({
d <- mydata %>%
filter(Name == input$Name)
updateCheckboxGroupInput(session, "Observation", choices = unique(d$Observation))
d
})
output$RepDimTable = renderTable({
repDimReactive = dat() %>%
filter(Observation %in% input$Observation) %>%
select(Observation, Date, Name, Colour, Score)
repDimReactive
})
})
我不确定如何从日期和观察列创建分支复选框。我尝试了 shinyTree 解决方案,但不知道如何将日期和观察结果嵌套到可用的列表形式中。
数据
mydata <- structure(list(Observation = 1:8, Date = c("2020-12-01", "2020-12-01",
"2020-12-01", "2021-01-01", "2021-01-01", "2021-01-01", "2021-01-15",
"2021-01-15"), Name = c("Bob", "Fred", "George", "Bob", "Bob",
"George", "Fred", "George"), Score = c(1L, 4L, 1L, 2L, 2L, 3L,
2L, 1L), Colour = c("Red", "Blue", "Blue", "Green", "Blue", "Blue",
"Green", "Red"), Year = c(2020L, 2020L, 2020L, 2021L, 2021L,
2021L, 2021L, 2021L), Month = c(12L, 12L, 12L, 1L, 1L, 1L, 1L,
1L), Day = c(1L, 1L, 1L, 1L, 1L, 1L, 15L, 15L)), row.names = c(NA,
8L), class = "data.frame", na.action = structure(9:22, .Names = c("9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22"), class = "omit"))