问题描述
我正在使用 facet_wrap() 为我的 Shiny 应用程序寻求一些帮助。我有一些数据 & 我希望应用程序使用从单个 selectInput 中选择的一个或多个变量动态 facet_wrap。 App 只使用一个变量而不是多个变量。当我从同一个 selectInput 中选择多个变量时,在图中只考虑第一个变量进行分面。我不想使用 facet_grid()。 有两件事我需要帮助。
- 当应用程序第一次启动时,我收到错误“错误:第一个参数无效”。如何摆脱这个错误。
- 如何使用从单个 selectInput 中选择的多个变量对图进行分面。 非常感谢任何建议或帮助。
Repex 代码:
library(shiny)
library(tidyverse)
library(DT)
# Define UI for data upload app ----
ui <- fluidPage(
titlePanel("Upload & View Files"),sidebarLayout(
sidebarPanel(width = 2,selectInput("facet","Select Facets",choices = colnames(data),"",multiple = T)
),# Main panel for displaying outputs ----
mainPanel("Data View",plotOutput("heatmap",width = "1050px",height = "800px"),DT::dataTableOutput("table")
)
)
)
# Define server logic to read selected file ----
server <- function(session,input,output) {
data <- diamonds
output$table <- DT::renderDataTable(data,options = list(paging = T,pageLength = 20))
output$heatmap <- renderPlot({
ggplot(data,aes(x = carat,fill = carat)) + geom_bar() + facet_wrap(~ get(input$facet),scales = "free")
})
}
shinyApp(ui,server)
我看到的是从 selectInput 中选择多个变量时;例如:切割、清晰度、深度等。就像拥有facet_wrap(~ cut + clarity + depth,scales = "free)
Error Message Multiple Facet required
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)