我正在构建一个闪亮的应用程序,我想在其中使用存储区列表。我想使用该存储桶列表是动态的,因为存储桶列表的选项仅是先前菜单选项中所选分区的工厂。因此,换句话说,当选择一个部门,遗愿清单上的选项将在某一特定部门改变,只有那些植物。
以下是此项目的示例闪亮应用程序。本质上,我想要的只是使第一级列表上的标签动态并在用户过滤除法时更改。我已经做了一些研究,但完全被困在这里。我的猜测是这并不难,但我很沮丧。任何帮助是极大的赞赏!
library(shiny)
library(tidyverse)
library(DT)
library(shinydashboard)
library(shinythemes)
library(sortable)
#dataframe for this sample:
data<- data.frame(division = c(1,1,1,1,2,2,2,2,3,3,3,3),
plant = c("a", "b", "c", "d", "a", "x", "m", "p", "c", "x", "a", "b"),
value = c(12,15,23,15,14,64,63,12,4, 18, 31, 1))
# Define UI for application that draws a histogram
ui <- dashboardPage(
dashboardHeader(title = "Test App"),
dashboardSidebar(
sidebarMenu(
menuItem("Data", tabName = "data"),
menuItem("Drag and Drop", tabName = "drag")
)
),
dashboardBody(
sidebarPanel(width = 3,
selectInput("division", "Select Division:", choices = c("all", 1,2,3))
),
tabItems(
tabItem(tabName = "data",
box(title = "Data", width = 9, status = "primary", height = "auto",
solidHeader = T, dataTableOutput("preview1"))
),
tabItem(tabName = "drag",
bucket_list(
header = "Interactive bucket list",
group_name = "bucket_list_group",
orientation = "horizontal",
add_rank_list(text = "Bucket 1",
labels = c("a", "b", "c"), input_id = "default"),
add_rank_list(text = "bucket 2",
labels = NULL,
input_id = "bucket2")
)
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
filtered<- reactive({
if(input$division == "all"){
data
} else{
data %>% filter(division == input$division)
}
})
output$preview1<-renderDataTable(
datatable(filtered(), options = list(searching = T, pageLength =10, scrollX = T))
)
}
# Run the application
shinyApp(ui = ui, server = server)
如果我做对了,那么您可以通过uiOutput
和renderUI
这样的方式来达到您想要的结果:
library(shiny)
library(tidyverse)
library(DT)
library(shinydashboard)
library(shinythemes)
library(sortable)
#dataframe for this sample:
data<- data.frame(division = c(1,1,1,1,2,2,2,2,3,3,3,3),
plant = c("a", "b", "c", "d", "a", "x", "m", "p", "c", "x", "a", "b"),
value = c(12,15,23,15,14,64,63,12,4, 18, 31, 1))
# Define UI for application that draws a histogram
ui <- dashboardPage(
dashboardHeader(title = "Test App"),
dashboardSidebar(
sidebarMenu(
menuItem("Data", tabName = "data"),
menuItem("Drag and Drop", tabName = "drag")
)
),
dashboardBody(
sidebarPanel(width = 3,
selectInput("division", "Select Division:", choices = c("all", 1,2,3))
),
tabItems(
tabItem(tabName = "data",
box(title = "Data", width = 9, status = "primary", height = "auto",
solidHeader = T, dataTableOutput("preview1"))
),
tabItem(tabName = "drag",
uiOutput("bucket")
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
filtered<- reactive({
if(input$division == "all"){
data
} else{
data %>% filter(division == input$division)
}
})
output$bucket <- renderUI({
bucket_list(
header = "Interactive bucket list",
group_name = "bucket_list_group",
orientation = "horizontal",
add_rank_list(text = "Bucket 1",
labels = unique(filtered()$plant), input_id = "default"),
add_rank_list(text = "bucket 2",
labels = NULL,
input_id = "bucket2")
)
})
output$preview1<-renderDataTable(
datatable(filtered(), options = list(searching = T, pageLength =10, scrollX = T))
)
}
# Run the application
shinyApp(ui = ui, server = server)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句