簡體   English   中英

閃亮的條件主面板

[英]Conditional Main Panel in Shiny

我正在構建一個Shiny App,我希望Main Panel是動態的,以便在選擇一個下拉菜單時創建一個新圖。 我知道在情節彼此重疊的地方怎么做(這很爛,因為我在下面有表格,而用戶必須向下滾動)。 如果“主面板圖”僅是“開關”,那就更好了。 我不確定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")


        )
)
)

是的,您肯定可以在mainPanel繪圖區域中使用條件面板。 您的代碼幾乎可以使用(只有一個或兩個錯誤的括號)。 下面是帶有偽圖的修訂代碼,以顯示其工作方式。 顯然,您將不得不更新實際需要的繪圖。 基本結構應該很清楚。 在用戶界面中,只需將您的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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM