闪亮的rcharts图表大小如何调整?

5

我正在接近实现我的目标,但现在我遇到了调整大小和对齐rChart输出的麻烦。目前,我的输出位于第二列的左下角。我希望输出居中于第二列,并且如果可能的话调整大小以更好地适应它。

这是我的ui.R:

require(rCharts)
shinyUI(fluidPage(
  titlePanel("Quiz 3 grades distribution"),

  fluidRow(
    column(3,
      #helpText("Select grade in Quiz 1 before the treatment:"),    
      selectInput("select", label = h3("Grade Quiz 1 before the treatment:"), 
                  choices = list("All" = 0, "Not Perfect" = 1, "Perfect" = 2), 
                  selected = 0)
    ),

    column(9, showOutput("histogram","nvd3"), class = "span6")
  )
))

感谢您的帮助!

请考虑提供一个可重现的示例。如果您的问题与Shiny有关,则可以使用runApp来实现此目的。 - jdharrison
1个回答

7
您可以使用 $params$width$params$height 选项来调整您的绘图大小。 使用 column(9 声明一个类为span9 ,与您的 span6 调用不兼容。 您可以使用CSS样式选项来对齐您的内容:
library(rCharts)
library(shiny)
X <- data.frame(Var1 = c(1L, 2L, 3L, 4L, 5L, 6L, 7L,8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L,3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L),
                Var2 = structure(c(1L,1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("control","treatment1", "treatment2"), class = "factor"),
                Freq = c(0L,0L, 3L, 2L, 6L, 9L, 13L, 36L, 50L, 497L, 0L, 2L, 1L, 3L, 6L, 4L, 11L, 29L, 50L, 499L, 1L, 2L, 0L, 2L, 5L, 6L, 12L, 22L, 63L,490L)
)
runApp(
  list(ui = fluidPage(
    titlePanel("Quiz 3 grades distribution"),

    fluidRow(
      column(3,
             #helpText("Select grade in Quiz 1 before the treatment:"),    
             selectInput("select", label = h3("Grade Quiz 1 before the treatment:"), 
                         choices = list("All" = 0, "Not Perfect" = 1, "Perfect" = 2), 
                         selected = 0)
      ),

      column(9, div(showOutput("histogram","nvd3")), style = 'align:center;')
    )
  ),
  server = shinyServer(
    function(input, output, session) {
      output$histogram <- renderChart2({
        n2 <- nPlot(Freq ~ Var1, group = 'Var2', data = X, type = 'multiBarChart')
        n2$params$width <- 500
        n2$params$height <- 400
        n2
      })
    }
  )

  )
)

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接