我有一个表的数据MegaP2的器官型,分为肺和皮肤,然后各种细胞类型,所有这些都来自肺或皮肤。我试图使细胞系下拉框中的可用选择只反映第一个下拉框中来自选定的器官的选项。
如果我选择皮肤或肺,就能很好地获得相关的细胞株,但如果我试图选择其他器官类型,则进一步限制细胞株仅限于两个器官中的细胞株,而不是将所有细胞株用于新器官的选择。它也阻止我点击细胞线下拉菜单进行修改。
我想我需要一些方法,使器官类型刷新时,新的选择,但任何帮助,将是非常感谢的。
我创建了这样的选择清单:
Cell_type = c("All", as.character(levels(MegaP2$Cell_line)))
Organ_type = as.character(levels(MegaP2$Organ))
Lung_cells = filter(MegaP2, Organ == "Lung")
#Then to remove the levels that have been filtered out
Lung_cells = droplevels(Lung_cells)
Lung_lines = c("All", as.character(levels(Lung_cells$Cell_line)))
Skin_cells = filter(MegaP2, Organ == "Skin")
Skin_cells = droplevels(Skin_cells)
Skin_lines = c("All", as.character(levels(Skin_cells$Cell_line)))我的(相关) ui代码如下所示:
ui = fluidPage(
titlePanel(title=div(img(src="cell_image.png", height = 140, width = 400), "The Senescent Cell")),
sidebarLayout(
sidebarPanel(
selectInput("OrganT",
label = "Organ",
choices = Organ_type,
multiple = T,
selected = "All"),
selectInput("Cell",
label = "Cell Line",
choices = Cell_type,
multiple = T,
selected = "All")
),
mainPanel(
tableOutput("MegaData")
)
)
)我的服务器代码如下所示:我在Select会话更新中保留了可能导致问题的情况,理想情况下,我希望它也能与这些更新一起工作。
server = function(input, output, session) {
selectedData <- reactive({
req(input$OrganT)
req(input$Cell)
MegaP2 %>%
dplyr::filter(Cell_line %in% input$Cell & Organ %in% input$OrganT)
})
output$MegaData = renderTable({
data = selectedData()
})
observe({
if("Lung" %in% input$OrganT & !"Skin" %in% input$OrganT)
choices2 = Cell_type[which(Cell_type %in% Lung_lines)]
else if("Skin" %in% input$OrganT & !"Lung" %in% input$OrganT)
choices2 = Cell_type[which(Cell_type %in% Skin_lines)]
else
choices2 = Cell_type
updateSelectInput(session, "Cell", choices = choices2, selected = choices2)
if("All" %in% input$Cell)
selected_choices6 = choices2[-1]
else
selected_choices6 = input$Cell
updateSelectInput(session, "Cell", selected = selected_choices6)
})
}发布于 2020-10-28 15:27:58
我认为您应该直接使用数据表来选择选择。也许你可以试试这个
ui = fluidPage(
titlePanel(title=div(img(src="cell_image.png", height = 140, width = 400), "The Senescent Cell")),
sidebarLayout(
sidebarPanel(
uiOutput("organt"),
uiOutput("cellt")
),
mainPanel(
tableOutput("MegaData")
)
)
)
server = function(input, output, session) {
df1 <- veteran
MegaP <- df1 %>% mutate(Organ=ifelse(trt==1,"Lung","Skin"))
output$organt <- renderUI({
selectInput("OrganT",
label = "Organ",
choices = unique(MegaP$Organ),
multiple = T,
selected = "All")
})
MegaP1 <- reactive({
data <- subset(MegaP, Organ %in% req(input$OrganT))
})
output$cellt <- renderUI({
selectInput("Cell",
label = "Cell Line",
choices = unique(MegaP1()$celltype),
multiple = T,
selected = "All")
})
selectedData <- reactive({
req(MegaP1(),input$Cell)
data <- subset(MegaP1(), celltype %in% input$Cell)
})
output$MegaData = renderTable({
selectedData()
})
}
shinyApp(ui = ui, server = server)https://stackoverflow.com/questions/64574600
复制相似问题