闪亮标签隐藏/显示

时间:2020-02-04 09:34:49

标签: r shiny shinydashboard

我创建了一个“隐藏选项卡”复选框,以隐藏我在服务器中提到过的条件的选项卡。在将默认值提到为TRUE或FALSE后,我想替换该复选框或隐藏该复选框。因此,一旦应用程序运行,用户将看不到隐藏的TABS。请查看下面的代码。

library(shiny)
library(shinydashboard)
library(datasets)

ui <- shinyUI(fluidPage(

  titlePanel("Test of Skills"),

  sidebarLayout(

    sidebarPanel(("Details Enter Page"),

                 checkboxInput(inputId = "hide_tab",label = "Hide 'Data Selected' tab"),

                 # selectInput(inputId = "hide_tab",label = "Hide 'Data Selected' tab",choices = c(TRUE,FALSE), multiple = FALSE),

                 selectInput("data", "Select the dataset which has to be selected for analysis", 

                             choices = c("iris" , "pressure" , "USArrests")),

                 radioButtons("color", "Select the color of the histogram", 
                              choices = c("green", "orange","red","pink")),

                 sliderInput("bins", "select the number of bins required for histogram", 
                             min = 5 , max = 25 , value = 5 , step = 1),

                 numericInput("obs" , "Select the number of observation required for dataset" , 

                              min = 5, max = 100 , value = 5 , step = 1),

                 submitButton("Confirm")),

    mainPanel((" Analysis Of the Dataset"),

              tabsetPanel(id = "my_tabs",type = c("pills"),

                          tabPanel("Summary", h1(textOutput("MysumHeader")) ,
                                   verbatimTextOutput("Mysum")),

                          tabPanel("Structure and Observation" , h1(textOutput("Mystrobsheader")),
                                   verbatimTextOutput("Mystr") , h1(textOutput("Myobsheader")), verbatimTextOutput("Myobs")),

                          tabPanel("Data Selected",tableOutput("Mydata")),

                          tabPanel("Histogram Plot"))
    ))))




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

  observeEvent(input$hide_tab,ignoreNULL = FALSE, ignoreInit = TRUE, {
    if(isTRUE(input$hide_tab)) {
      shiny::hideTab(inputId = "my_tabs",
                     target = "Summary")
      shiny::hideTab(inputId = "my_tabs",
                     target = "Histogram Plot")
    } else {
      shiny::showTab(inputId = "my_tabs",
                     target = "Summary")
      shiny::showTab(inputId = "my_tabs",
                     target = "Histogram Plot")
    }

  })

  output$Mysum <- renderPrint({

    summary(get(input$data))
  })
  output$MysumHeader <- renderText({

    paste("The Dataset which is selected for analysis" , input$data)
  })

  output$Mystr <- renderPrint({

    str(get(input$data))
  })

  output$Mystrobsheader <- renderText({

    paste("DataSet selected for structure is " , input$data)
  })

  output$Myobs <- renderPrint({

    head(get((input$data)))

  })

  output$Myobsheader <- renderText({

    paste("First" , input$obs , "Selected from the datase" , input$data)

  })

  output$Mydata <- renderTable({

    View(get(input$data))
  })

})

shinyApp(ui,server)

0 个答案:

没有答案