Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

r - Shiny: How to adjust the width of the tabsetPanel?

Here is my app embedded in my site. I want to get rid of the scroll widget below my app, this is due to the width of the tabsetPanel.

I embed the app using this code:

<iframe width="800" height="480" frameborder="0" src="http://spark.rstudio.com/alstated/meanvar/"></iframe>

App Codes:

ui.R

library(shiny)

# Define UI for application that plots random distributions 
shinyUI(pageWithSidebar(
  headerPanel(title = ""),
  sidebarPanel(
    sliderInput("size",
                "Number of Observations",
                min = 10,
                max = 200,
                value = 95),

    sliderInput("mu",
                "Mean",
                min = -100, 
                max = 100,
                value = 0),

    sliderInput("sd",
                "Standard Deviation",
                min = 1,
                max = 6,
                value = 3),

    checkboxInput(inputId = "indiv_obs",
                  label = "Show individual observations",
                  value = FALSE),

    checkboxInput(inputId = "density",
                  label = "Show density estimate",
                  value = FALSE),

    conditionalPanel(condition = "input.density == true",
                     sliderInput(inputId = "bw_adjust",
                                 label = "Bandwidth Adjustment",
                                 min = 0.2,
                                 max = 2,
                                 value = 1,
                                 step = 0.2))
  ),
  mainPanel(
    tabsetPanel(
      tabPanel("Plot", 
               plotOutput(
                 outputId = "histogram", 
                 height = "400px",
                 width = "400px")),
      tabPanel("Summary",
               verbatimTextOutput(outputId = "datsummary"))
    ))
)
)

server.R

library(shiny)

# Define server logic required to generate and plot a random distribution
shinyServer(function(input, output) {

  data <- reactive(rnorm(
    n = input$size, 
    mean = input$mu, 
    sd = input$sd
  ))

  output$histogram <- renderPlot({

    hist(data(),
         probability = TRUE,
         xlab = "Data",
         ylab = "Density",
         main = "Histogram of Random Samples")

    if(input$indiv_obs){
      rug(data())
    }

    if(input$density){
      dens <- density(data(), adjust = input$bw_adjust)
      lines(dens, col = "blue")
    }

  })

  output$datsummary <- renderPrint(summary(data()))
})

Any help is greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I figure it now, I inspect the html code of the app on Shiny Homepage. And the tabsetPanel is adjusted using the <div> (Document Division) tag in html by setting the option class to either span1, span2, span3 and so on. The higher the suffix of the span the larger the width of the division. And I just add div() tag in my ui.R code:

div(
      tabsetPanel(
        tabPanel("Plot", 
                 plotOutput(
                   outputId = "histogram", 
                   height = "400px",
                   width = "400px")),
        tabPanel("Summary",
                 verbatimTextOutput(outputId = "datsummary"))
        ), class = "span7")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...