Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny rcharts size of the graph?

Tags:

r

shiny

rcharts

I'm getting closer to produce what I want, but Now i'm having troubles resizing and aligning the rChart output. Right now my output is in the lower left corner of my second column. I would like the output to be centered in the second column and if possible to get resized to fit it better.

This is my 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")
  )
))

Thanks for the help!

like image 733
Ignacio Avatar asked Jun 08 '14 10:06

Ignacio


1 Answers

You can adjust the size of your plot using $params$width and $params$height options. Your span6 call is not compatible with column(9 which will declare a class of span9. You can use a CSS style option to align your content:

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

like image 153
jdharrison Avatar answered Nov 19 '22 05:11

jdharrison