Plotting within tabsetpanel

Hi,
Any help would be greatly appreciated.

I am trying to plot within tab panel "Benefits" lines 61 -85 with multiple tabs within this tab.
I tried with the first tab for i.e. "bio" but no plot actually appears.


shinyUI(fluidPage(theme = shinytheme("flatly"),
  #application title
  titlePanel(HTML("<center>uk</center>")),
  sidebarLayout(
    sidebarPanel("CT"),
    mainPanel(tabsetPanel(type ="tabs", 
                  tabPanel("Home", icon = icon("home"),
                           titlePanel("Welcome"),
                  div(includeMarkdown("about.Rmd"),
                     align="justify" )),
                  tabPanel("Dashboard", icon = icon("table"),
                           #input values
                           sidebarPanel(HTML("<center>Choose the parameters for each of the following indicators</center>"), width = 20,
                             sliderInput("parS",
                                         label ="ParS (ha)",
                                         value = 2,
                                         min = 5,
                                         max =1000),
                             selectInput("AW",
                                         label ="AW",
                                         choices = list("Yes" =  "TRUE", "No" = "FALSE"),
                                         selected = "TRUE"),
                             sliderInput("pS",
                                         label ="PS ('000s)",
                                         value= 2,
                                         min = 1,
                                         max = 100),
                             sliderInput("distance",
                                         label ="Distance (kms)",
                                         value= 2,
                                         min = 1,
                                         max = 100),
                             sliderInput("proximity",
                                         label ="Proximity  (kms)",
                                         value= 2,
                                         min = 1,
                                         max = 100),
                             actionButton("submitbutton",
                                          "Submit",
                                          class = "btn btn-primary")
                           )), 
                  
                  tabPanel("Benefits", icon = icon("stats", lib = "glyphicon"),
                           
                           tabsetPanel(
                    tabPanel("Bio",
                             titlePanel("Conditional panels"),
                             
                             column(4, wellPanel(
                               sliderInput("n", "Number of points:",
                                           min = 10, max = 200, value = 50, step = 10)
                             )),
                             
                             column(5,
                                    "abun",
      
                                    conditionalPanel("input.n >= 50",
                                                     plotOutput("scatterPlot")
                                    )
                             )
                    ),
                    
                    tabPanel("Com",
                             sliderInput("tim",
                                         label ="Tim(GBP)",
                                         value= 2,
                                         min = 1,
                                         max = 100)
                             #actionButton("submitbutton",
                                         # "Submit",
                                         # class = "btn btn-primary")
                             
                             ),
                    tabPanel("Rec",
                             sliderInput("HW",
                                         label ="Tour(GBP)",
                                         value= 2,
                                         min = 1,
                                         max = 100)
                             
                              ),
                    tabPanel("Hist",
                             sliderInput("HP",
                                         label ="Tour(GBP)",
                                         value= 2,
                                         min = 1,
                                         max = 100)
                             
                    )
                    
                    )),
                     
                  tabPanel("Weighing",  icon = icon("cog"),
                           numericInput("obs","Tim:", 0.5, min = 0.0, max = 1),
                           verbatimTextOutput("value"),
                           numericInput("obs","Bio:", 0.25, min = 0, max = 1),decimalPlaces = 2,
                           verbatimTextOutput("value"),
                           numericInput("obs","HW:", 0.25, min = 0, max = 1),
                           verbatimTextOutput("value"),
                           numericInput("obs","HP:", 0.25, min = 0, max = 1),
                           verbatimTextOutput("value"),
                           
                  ),      
                  tabPanel("Output",
                           tags$label(h3('status/output')),#status
                           verbatimTextOutput('contents'),
                           tableOutput('tabledata')
                           )
                  
                  ))
    #textOutput("year"),plotOutput("rate"),textOutput("remark"))
     )
  
  
)
)





shinyServer(
  
  function(input, output){
 
    output$plotBio <- renderPlot({
      x <- rnorm(input$n)
      y <- rnorm(input$n)
      plot(x, y)
    })
    
  }
  
)

There are two issues regarding your above code:

  1. different names for plotOutput("scatterPlot") and output$plotBio <- renderPlot
  2. duplicated id's for verbatimTextOutput("value") - you will need to provide unique id's for each output.

Every now and then it is useful to check the browsers console:

image

Please check the following:

library(shiny)
library(shinythemes)

ui <- fluidPage(
  theme = shinytheme("flatly"),
                #application title
                titlePanel(HTML("<center>uk</center>")),
                sidebarLayout(sidebarPanel("CT"),
                              mainPanel(tabsetPanel(
                                type = "tabs",
                                tabPanel(
                                  "Home",
                                  icon = icon("home"),
                                  titlePanel("Welcome"),
                                  # div(includeMarkdown("about.Rmd"), align="justify" )),
                                  tabPanel(
                                    "Dashboard",
                                    icon = icon("table"),
                                    #input values
                                    sidebarPanel(width = 20, 
                                                 HTML("<center>Choose the parameters for each of the following indicators</center>"),
                                      sliderInput(
                                        "parS",
                                        label =
                                          "ParS (ha)",
                                        value = 5,
                                        min = 5,
                                        max = 1000
                                      ),
                                      selectInput(
                                        "AW",
                                        label =
                                          "AW",
                                        choices = list("Yes" =  "TRUE", "No" = "FALSE"),
                                        selected = "TRUE"
                                      ),
                                      sliderInput(
                                        "pS",
                                        label =
                                          "PS ('000s)",
                                        value = 2,
                                        min = 1,
                                        max = 100
                                      ),
                                      sliderInput(
                                        "distance",
                                        label =
                                          "Distance (kms)",
                                        value = 2,
                                        min = 1,
                                        max = 100
                                      ),
                                      sliderInput(
                                        "proximity",
                                        label =
                                          "Proximity  (kms)",
                                        value = 2,
                                        min = 1,
                                        max = 100
                                      ),
                                      actionButton("submitbutton",
                                                   "Submit",
                                                   class = "btn btn-primary")
                                    )
                                  ),
                                  tabPanel(
                                    "Benefits",
                                    icon = icon("stats", lib = "glyphicon"),
                                    tabsetPanel(
                                      tabPanel(
                                        "Bio",
                                        titlePanel("Conditional panels"),
                                        column(4, wellPanel(
                                          sliderInput(
                                            "n",
                                            "Number of points:",
                                            min = 10,
                                            max = 200,
                                            value = 50,
                                            step = 10
                                          )
                                        )),
                                        column(5,
                                               "abun",
                                               conditionalPanel(
                                                 "input.n >= 50",
                                                 plotOutput("plotBio")
                                               )
                                        )
                                      ),
                                      tabPanel(
                                        "Com",
                                        sliderInput(
                                          "tim",
                                          label =
                                            "Tim(GBP)",
                                          value = 2,
                                          min = 1,
                                          max = 100
                                        )
                                        #actionButton("submitbutton",
                                        # "Submit",
                                        # class = "btn btn-primary")
                                      ),
                                      tabPanel(
                                        "Rec",
                                        sliderInput(
                                          "HW",
                                          label =
                                            "Tour(GBP)",
                                          value = 2,
                                          min = 1,
                                          max = 100
                                        )
                                      ),
                                      tabPanel(
                                        "Hist",
                                        sliderInput(
                                          "HP",
                                          label =
                                            "Tour(GBP)",
                                          value = 2,
                                          min = 1,
                                          max = 100
                                        )
                                      )
                                    )
                                  ),
                                  tabPanel(
                                    "Weighing",
                                    icon = icon("cog"),
                                    numericInput("obs", "Tim:", 0.5, min = 0.0, max = 1),
                                    # verbatimTextOutput("value"), # <- issue
                                    numericInput("obs", "Bio:", 0.25, min = 0, max = 1),
                                    decimalPlaces = 2,
                                    # verbatimTextOutput("value"), # <- issue
                                    numericInput("obs", "HW:", 0.25, min = 0, max = 1),
                                    # verbatimTextOutput("value"), # <- issue
                                    numericInput("obs", "HP:", 0.25, min = 0, max = 1),
                                    verbatimTextOutput("value") # <- issue
                                  ),
                                  tabPanel(
                                    "Output",
                                    tags$label(h3('status/output')),
                                    #status
                                    verbatimTextOutput('contents'),
                                    tableOutput('tabledata')
                                  )
                                )
                              )
                              # textOutput("year"),plotOutput("rate"),textOutput("remark"))
                              )
                )
)

server <- function(input, output, session) {
  output$plotBio <- renderPlot({
    x <- rnorm(input$n)
    y <- rnorm(input$n)
    plot(x, y)
  })
}

shinyApp(ui, server)
2 Likes

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.