设置shiny有点困难。不确定错误发生在哪里,请查看下面的信息:
获得以下与facet_grid相关的错误:
Warning: Error in combine_vars: At least one layer must contain all faceting variables: `input$Cancer`
✖ Plot is missing `input$Cancer`
✖ Layer 1 is missing `input$Cancer`
但是,如果我删除facet_grid,它将生成一个空图,因此我认为selectInput
、data_selected
或ggplot
有问题
示例数据:
files.Vir.DNA.df.test <- structure(list(ID = c("NC_010277.2", "NC_010277.2", "NC_010277.2",
"NC_010277.2", "NC_010277.2", "NC_010277.2", "NC_010277.2", "NC_010277.2",
"NC_010277.2", "NC_010277.2", "NC_010277.2", "NC_010277.2", "NC_010277.2",
"NC_010277.2", "NC_010277.2", "NC_010277.2", "NC_010277.2", "NC_010277.2",
"NC_010277.2", "NC_010277.2"), rowSums = c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
Cancer = c("Adrenal gland", "Adrenal gland", "Adrenal gland",
"Adrenal gland", "Adrenal gland", "Adrenal gland", "Adrenal gland",
"Adrenal gland", "Adrenal gland", "Adrenal gland", "Adrenal gland",
"Adrenal gland", "Adrenal gland", "Adrenal gland", "Adrenal gland",
"Adrenal gland", "Adrenal gland", "Adrenal gland", "Adrenal gland",
"Adrenal gland"), position = c(1000, 1001, 1002, 1003, 1004,
1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014,
1015, 1016, 1017, 1018, 1019), V1 = c("Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b", "Merkel_cell_polyomavirus_isolate_R17b",
"Merkel_cell_polyomavirus_isolate_R17b"), Length = c(5387L,
5387L, 5387L, 5387L, 5387L, 5387L, 5387L, 5387L, 5387L, 5387L,
5387L, 5387L, 5387L, 5387L, 5387L, 5387L, 5387L, 5387L, 5387L,
5387L)), row.names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20"), class = "data.frame")
用户界面:
ui <- dashboardPage(
# Application title
dashboardHeader(title=h4(HTML("Virus Coverage plot"))),
dashboardSidebar(
useShinyjs(),
selectInput("Taxa", "Taxa", choices = unique(files.Vir.DNA.df.test$V1)),
shinyjs::hidden(selectInput("Taxa", "Taxa", choices = c("Taxa")))
),
dashboardBody(
tabsetPanel(
tabPanel("Taxa", plotOutput("myplot1", width = "400px", height = "300px"))
)
)
)
服务器:
server <- function(input, output, session) {
data_selected <- reactive({
filter(files.Vir.DNA.df.test, V1 %in% input$V1)
})
output$myplot1 <- renderPlot({
ggplot(data_selected(), aes_string(input$V1, "position", fill = input$V1)) +
scale_y_log10(breaks = c(1,100,10000)) +
theme_classic(base_size = 6) +
geom_bar(stat="identity") +
facet_grid(Cancer~. , scales = "free_x", space = "free_x", switch = "x")
})
}
shinyApp(ui, server)
1条答案
按热度按时间8hhllhi21#
正如在评论中指出的,代码有很多问题,但下面将根据选定的分类群生成图。我不太确定您在那里试图用
shinyjs::hidden
做什么。