Блестящая и блестящая панель: Как отображать входные данные в боковой панели только на определенных вкладках? - PullRequest
0 голосов
/ 19 апреля 2020

Я хочу отображать входные данные (флажки, выбрать входные данные) на боковой панели моей блестящей панели инструментов, но только при нажатии определенной вкладки.

Пример минимального воспроизводимого изображения ниже. Как я могу установить флажки и выбрать вход, который будет отображаться только на странице 2?

#ui.R

library(shiny)
library(shinydashboard)

# Define UI for application that draws a histogram
shinyUI(dashboardPage(
    dashboardHeader(title = "Test Application",
                    titleWidth = "400px"
    ),

    dashboardSidebar(
        id = "navbar",
        menuItem("Page 1", tabName = "page1"),
        menuItem("Page 2", tabName = "page2"),

        # THESE SHOW UP ALL THE TIME - HOW TO GET JUST ON PAGE 2?
        checkboxGroupInput("outcome", "Select Outcome Variable(s):", choices = c("Box 1", "Box 2", "Box 3")),
        selectInput("selectinput", label = "Select:", choices = c("Choice 1", "Choice 2", "Choice 2"))


    ),

    dashboardBody(
        tabItems(
            tabItem(
                tabName = "page1",
                h1("This is page 1")
            ),

            tabItem(
                tabName = "page2",
                h1("This is page 2")
            )
        )
    )
))

Я предполагаю, что здесь что-то нужно, чтобы входные данные были динамичными c?

# server.R

library(shiny)

# Define server logic required to draw a histogram
shinyServer(function(input, output) {
})

Ответы [ 2 ]

0 голосов
/ 19 апреля 2020

ОТВЕТ: используйте условную панель, которая запрашивает выбранную вкладку.

Credit: Mine в Rstudio

library(shiny)
library(shinydashboard)

# ui ---------------------------------------------------------------------------

ui <- dashboardPage(

  # title ----
  dashboardHeader(title = "Test Application"),

  # sidebar ----
  dashboardSidebar(
    sidebarMenu(id = "sidebarid",
                menuItem("Page 1", tabName = "page1"),
                menuItem("Page 2", tabName = "page2"),
                conditionalPanel(
                  'input.sidebarid == "page2"',
                  sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30),
                  selectInput("title", "Select plot title:", choices = c("Hist of x", "Histogram of x"))
                )
    )
  ),

  # body ----
  dashboardBody(
    tabItems(
      # page 1 ----
      tabItem(tabName = "page1", "Page 1 content. This page doesn't have any sidebar menu items."),
      # page 2 ----
      tabItem(tabName = "page2", 
              "Page 2 content. This page has sidebar meny items that are used in the plot below.",
              br(), br(),
              plotOutput("distPlot"))
    )
  )
)

# server -----------------------------------------------------------------------

server <- function(input, output, session) {

  output$distPlot <- renderPlot({
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    hist(x, breaks = bins, col = "darkgray", border = "white", main = input$title)
  })

}

# shiny app --------------------------------------------------------------------

shinyApp(ui, server)
0 голосов
/ 19 апреля 2020

Если я правильно понял ваш вопрос, все, что вам нужно сделать, это следующее: при определении dashboardSidebar, если вы просто хотите использовать его в качестве навигационной панели, добавьте sidebarmenu(), а затем добавьте пункты вашего меню.

Затем, чтобы флажки и выбор входных данных отображались только для главной панели инструментов на стр. 2, добавьте их в dashboardbody() с tabItem = "page2". Смотрите ниже:

#ui.R

library(shiny)
library(shinydashboard)

# Define UI for application that draws a histogram
ui<- dashboardPage(

dashboardHeader(title = "Test Application",titleWidth = "400px"),

dashboardSidebar(
 sidebarMenu(    #Add sidebarMenu here!!!!!
 menuItem("Page 1", tabName = "page1", icon = icon("dashboard")), # You can add icons to your menu if you want
 menuItem("Page 2", tabName = "page2", icon = icon("dashboard")))),

dashboardBody(
 tabItems(

    tabItem(
     tabName = "page1",
     h1("This is page 1")),

   tabItem( #Add checkboxGroupInput into this tabItem 
     tabName = "page2",
     h1("This is page 2"),
     checkboxGroupInput("outcome", "Select Outcome Variable(s):", choices = c("Box 1", "Box 2", "Box 3")),
     selectInput("selectinput", label = "Select:", choices = c("Choice 1", "Choice 2", "Choice 2")))
 )
))

server <- function(input,output,session) {

}

shinyApp(ui, server)
...