Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tabsetPanel within a fluidPage not working

I'm trying to set up a shiny vis with two panels.

I would also like, within each panel, to use a fluidPage layout, where I can have columns.

I went ahead and attempted this. But my code isn't working quite right.

I am ending up with one page, where there are 2 tabs, and neither of them work. Further, neither tab has the text that one would expect to be present.

Here is an screenshot of my shiny app. Note the tabs up on the top, which are doing nothing useful:

enter image description here

How can I get the tabs to interact properly? Is there any way to have 2 tabs, and within each tab, use the fluidPage functions to create custom rows and columns?

UI.R

shinyUI(fluidPage(
  titlePanel("Shiny Viz!"),

  mainPanel(

    tabsetPanel(
    fluidRow(
      column(4,
      tabPanel("Controls", checkboxGroupInput("select", label="", choices = list("Age" = "Age", "Weight" = "Weight", "Circumference" = "Circumference"), inline=TRUE))),

      column(4,
      plotOutput("select"))               
               ))),

    tabsetPanel(
    fluidRow(
      column(4,
      tabPanel("output_at_some_point"))))
  ))

SERVER.R

library(shiny)
library(ggplot2)

DF <- as.data.frame(matrix(c(1:9),ncol=3,nrow=3))
DF <- data.frame(replicate(3,1:3))
names(DF) <- c("Age", "Weight", "Circumference")

shinyServer(function(input, output) {  

  output$select <- renderPlot({

    # modify DF
    DF_with_tests_selected <- subset(DF, select = input$select)

    #ggplot
     p <- ggplot(DF)
     p <- p + geom_segment(aes(x=1, xend=1, y=2, yend=3))

    plot(p) 
    }) 
})  
like image 366
tumultous_rooster Avatar asked Dec 03 '14 22:12

tumultous_rooster


Video Answer


2 Answers

I am not quite sure that I understand what you expect your app to look like, so I can't tell you what was wrong with your code. However, I can answer this question:

Is there any way to have 2 tabs, and within each tab, use the fluidPage functions to create custom rows and columns?

Yes it is possible, see the example. Note that I use fluidRow instead of the mainPanel, but I am not sure if it make much of a difference. Also, this is a single-file shiny app. I would put a screenshot off the app, but it seem that I can't.

 # UI components.
ui <- fluidPage(
titlePanel("Shiny Viz!"),

fluidRow( class= "R1",
tabsetPanel(type= "pills",

        tabPanel("Controls",
                 fluidRow(column(4, offset=1, selectInput("X", label="x var", 
                                      choices = list("Age" = "Age", "Weight" = "Weight", "Circumference" = "Circumference"),
                                      multiple=F) ),
                          column(4,selectInput("Y", label="y var", 
                                       choices = list("Age" = "Age", "Weight" = "Weight", "Circumference" = "Circumference"),
                                       multiple=F))) ,
                 fluidRow(column(5, offset=1, plotOutput("plot", height = "400px") ),
                          column(5, class= "R2C2", helpText("This is an exemple") ) ) ),
        tabPanel("output_at_some_point",
                 div(style = "height:800px; background-color: yellow;", "This is an example")))  

  ), tags$head(tags$style(".R2C2{height:250px; background-color: red;}
                      .R1{background-color: lightgray;}"))
)



library(ggplot2)
 # Create fake data
DF <- data.frame( Age = rnorm(50, 45, 20), Weight= runif(50, 50 , 200), Circumference =  runif(50, 30 , 100) )  

 # server component
server <- function(input, output) {  
 output$plot <- renderPlot({
   DF$X <- DF[, which(names(DF) == input$X)]
   DF$Y <- DF[, which(names(DF) == input$Y)]   
ggplot(DF, aes( x= X, y= Y)) + geom_point() + labs(list(x = input$X, y = input$Y))
 } )
} 


shinyApp(ui=ui, server=server)
like image 150
S. Venne Avatar answered Oct 03 '22 04:10

S. Venne


Check out the gallery example here

I believe you're missing a few things:

tabsetPanel(type="tabs",
    tabPanel("name of panel",

etc.

like image 45
misanuk Avatar answered Oct 03 '22 05:10

misanuk