我是闪亮和R的新手。我正在创建一个动态的闪亮仪表板。在这里,用户需要从第一张表中选择一行,并且单元格值很少,因此用户必须对其他数据进行过滤,然后它才能继续。 从用户创建的新第二张表中,再次在第二张表中选择一行。所选行中的某些值用于过滤现有数据集并以闪亮的形式显示。等等。
我写了一个示例代码,但是没有用。
df <- data.frame(id = sample(c(1,2,3,4),15, replace = T ),
day = sample(c("Mon", "Tue", "Wed"),15, replace = T),
hour_hand = c(0:14),
price =sample(c(121,221,112,231,444), replace = T))
df_day <- df %>%
group_by(id) %>%
summarise(price = sum(price))
df_day_hour <- df %>%
group_by(id, day) %>%
summarise(price = sum(price))
ui <- dashboardPage(skin = "red",
dashboardHeader(title = "2_level_drill_down"),
dashboardSidebar(sidebarMenu(menuItem("Price", tabName = "tab_01", icon =icon("bar-chart")))),
dashboardBody(tabItems(
tabItem(tabName = "tab_01",
tabsetPanel(
tabPanel("Id", DT::dataTableOutput("table_id")),
tabPanel("ID Day", DT::dataTableOutput("table_id_day")),
tabPanel("ID Day Hour",DT::dataTableOutput ("table_id_day_hour"))))
)))
server <- function(input, output){
#Id table
output$table_id <- renderDT(DT::datatable({
data =df
}))
#Id Day group_by table
output$table_id_day <- renderDT(DT::datatable({
s = input$table_id_rows_selected
v <- unique(df[s,c("id")])
data = df_day[df_day$id %in% v,]
}))
#ID Day Hour group_by Table
output$table_id_day_hour <- renderDT({
s_3 = input$table_nodal_day_rows_selected
id_3 <- unique(id_day_df[s_2,c("id")])
day_2 <- unique(id_day_df[s_2,c("day")])
data = df_day_hour[df_day_hour$id %in% id_3 & df_day_hour$day %in% day_2,]
})
}
#####
shinyApp(ui,server)