这是我的app嵌入在我的网站中。我想摆脱我应用下方的滚动小部件,这是由于tabsetPanel的宽度所致。

我使用以下代码嵌入了该应用程序:

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

应用程式码:

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"))
    ))
)
)

服务器。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()))
})

任何帮助是极大的赞赏!

最佳答案

我现在知道了,我在Shiny Homepage上检查了应用程序的html代码。通过将选项<div>设置为classspan1span2等,可以使用html中的span3(文档分区)标签来调整tabsetPanel。 span的后缀越高,划分的宽度越大。我只是在ui.R代码中添加div()标签:

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

关于r - Shiny :如何调整tabsetPanel的宽度?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19096439/

10-12 17:55