更改使用rCharts生成的图形的高度属性,以便与rshiny一起使用

use*_*452 4 r shiny rcharts

我正在使用rCharts在rshiny中实现交互式图形.我正在使用morris库这是我的问题的一个最小例子:

## ui.R
require(rCharts)
shinyUI(pageWithSidebar(
  headerPanel("rCharts: Interactive Charts from R using morris.js"),

  sidebarPanel(
  ),
  mainPanel(
    showOutput("myChart", "morris")
  )
))

require(rCharts)
shinyServer(function(input, output) {
  output$myChart <- renderChart({
    data(economics, package = 'ggplot2')
    econ <- transform(economics, date = as.character(date))
    m1 <- mPlot(x = 'date', y = c('psavert', 'uempmed'), type = 'Line',
                data = econ)
    m1$set(pointSize = 0, lineWidth = 1)
    m1$addParams(dom = 'myChart')
    m1$params$width = 200
    m1$params$height = 200
    return(m1)
  })
})
Run Code Online (Sandbox Code Playgroud)

如果m1对象没有被发送到闪亮,则高度和宽度组件可以正常工作,但是在处理之后它们似乎被忽略了renderChart.我使用样式表进行了临时修复:

.shiny-html-output.morris{
  height: 200px;
  width: 200px;
}
Run Code Online (Sandbox Code Playgroud)

我有什么选择吗?例如,plotOutputshiny包中你可以规定:plotOutput("plot2", height = "260px")例如.

use*_*452 5

这是目前将被添加到rCharts的功能.作为临时修复,我在样式表中添加了一个条目,以实现我的应用程序上的两个morris图.将www /文件夹添加到您的app目录并创建一个styles.css文件.加

 tags$head(
   tags$link(rel = 'stylesheet', type = 'text/css', href = 'styles.css')
 ),
Run Code Online (Sandbox Code Playgroud)

ui.R和地方

.shiny-html-output.morris{
  height: 200px;
  width: 200px;
}
Run Code Online (Sandbox Code Playgroud)

styles.css