Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rstudio shiny conditionalPanel for mainPanel

Tags:

r

shiny

I am trying to create a shiny web page that will have two different main and side panels. So when choosing "Case A" in the sidebarPanel, I want a specific mainPanel with a specific tabsetPanel, that will be different if I choose "Case B". After reading the documentation, I got stuck at this point:

ui.R:

shinyUI(pageWithSidebar(
  headerPanel("This is a Shiny page"),
  sidebarPanel(
     selectInput(
        "plotType", "Plot Type",
        c("Case A","Case B")
         )
  ),
  mainPanel(
    conditionalPanel(
      condition(input.plotType == 'Case A'),
       tabsetPanel(
         tabPanel("A1",
           textOutput("This is conditionalPanel A1")
                  ),
         tabPanel("A2",
           textOutput("This is conditionalPanel A2")
                  )
         )
     ),
    conditionalPanel(
      condition(input.plotType == 'Case B'),
      tabsetPanel(
        tabPanel("B1",
          textOutput("This is conditionalPanel B1")
                  ),
        tabPanel("B2",
          textOutput("This is conditionalPanel B2")
                  )
      )
    )
  )
))

server.R:

shinyServer(function(input, output) {
})

I am getting this error:

Listening on port 50709
Error in tag("div", list(...)) : could not find function "condition"
Calls: runApp ... tag -> conditionalPanel -> div -> <Anonymous> -> tag
Error in setwd(orig.wd) : cannot change working directory
Calls: runApp ... conditionalPanel -> div -> <Anonymous> -> tag -> setwd
Execution halted

Any ideas what am I missing?

like image 601
719016 Avatar asked Nov 01 '13 09:11

719016


1 Answers

It turns out I was taking an example using this nomenclature:

condition(input.plotType == 'Case B')

whereas if I change it to this, then it works:

condition = "input.plotType=='Case B'"
like image 130
719016 Avatar answered Nov 08 '22 10:11

719016