【问题标题】:Conditional Main Panel in ShinyShiny 中的条件主面板
【发布时间】:2018-11-29 02:18:48
【问题描述】:

我正在构建一个闪亮的应用程序,我希望主面板是动态的,使得选择一个下拉菜单时,创建了新的绘图。我了解如何在图相互重叠的情况下进行操作(这很糟糕,因为我在其下方有表格并且用户必须向下滚动)。如果主面板图只是“切换”,那就太好了。我不确定 ConditinalPanel 是否可以在这里工作?甚至是 Switch 语句?这是我的用户界面。

source("DATA CLEANING.R")

salespeople <- sort(unique(salesdatav3$SALESPERSON))


# Define UI for application that draws a histogram
ui <- fluidPage(theme = shinytheme("united"),

   # Application title
   titlePanel("Pounds_New"),

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
        pickerInput("slsp", "SalesPerson", choices = salespeople, selected =NULL, options = list(`actions-box` = TRUE), multiple = T),


      pickerInput("stats", "Summary Stats", choices = as.vector(c("Positive/Negative Count", "Histogram", "Plot Pounds by Time", "Top Ten Positive Trending",
                                                        "Top Ten Negative Trending")), selected = NULL, multiple = F, list(`actions-box` = TRUE))

      ),

      # Show a plot of the generated distribution
        mainPanel(
          plotOutput("sidebarplot"),
          # conditionalPanel(
          #   condition =  "input.stats == 'Histogram'",
          #   plotOutput("histt"),

          # conditionalPanel(
          #   condition = "input.slsp",
            DT::dataTableOutput("data_table"),
          plotOutput("plot_pounds")


        )
)
)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    是的,您当然可以在 mainPanel 绘图区域中使用条件面板。您的代码非常接近可行(只有一两个错误的括号)。下面是修改后的代码和虚拟图,以显示它是如何工作的。你显然必须更新你真正想要的情节。基本结构应该很清楚。在 UI 中,只需将您的 conditionalPanels 包含在 mainPanel 项目中,然后在服务器中单独指定您的地块。

    用户界面:

    library(shiny)
    library(shinythemes)
    library(shinyWidgets)
    ui <- fluidPage(theme = shinytheme("united"),
    
                # Application title
                titlePanel("Pounds_New"),
    
                # Sidebar with a slider input for number of bins 
                sidebarLayout(
                  sidebarPanel(
                    pickerInput("slsp", "SalesPerson", choices = c("a","b","c","d"), selected =NULL, options = list(`actions-box` = TRUE), multiple = T),
    
    
                    pickerInput("stats", "Summary Stats", choices = as.vector(c("Positive/Negative Count", "Histogram", "Plot Pounds by Time", "Top Ten Positive Trending",
                                                                                "Top Ten Negative Trending")), selected = NULL, multiple = F, list(`actions-box` = TRUE))
    
                  ),
    
                  # Show a plot of the generated distribution
                  mainPanel(
                    conditionalPanel(
                      condition = "input.stats == 'Positive/Negative Count'",
                      plotOutput("sidebarplot")
                    ),
                    conditionalPanel(
                      condition =  "input.stats == 'Histogram'",
                      plotOutput("histt")
                    ),
                    conditionalPanel(
                      condition = "input.slsp",
                      # DT::dataTableOutput("data_table"),
                      plotOutput("plot_pounds")
                    )
                  )
                )
    )
    

    服务器:

    server <- function(input, output) {
      output$sidebarplot <- renderPlot({
        hist(rnorm(50),10)
      })
    
      output$histt <- renderPlot({
        hist(runif(50),10)
      })
    
      output$plot_pounds <- renderPlot({
        hist(rbeta(50,1,5),10)
      })
    
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 哦,伙计,我希望有人能回答。谢谢!发现。 :)
    猜你喜欢
    • 2016-09-29
    • 2016-08-14
    • 2015-07-07
    • 2016-06-04
    • 2020-06-03
    • 2014-11-18
    • 2013-11-03
    • 1970-01-01
    • 2016-04-12
    相关资源
    最近更新 更多