2016-07-29 58 views
0

我似乎无法弄清楚如何改变使用metricsgraphics软件包创建的直方图的颜色。我已经建立了一个功能闪亮的应用程序,使用规范和导出代码下面呈现的柱状图:如何更改mjs_histogram栏颜色(使用metricsgraphics r软件包)?

mjs_plot(zedata()$Value, format="count") %>% 
     mjs_histogram(bins = 10) %>% 
     mjs_labs(x=input$item, y="Number of VA Medical Centers") 

我增添了不少色彩=“#d7191c” mjs_plot和mjs_histogram无济于事 - 我两次都得到了一个未使用的参数错误。我在hrbrmstr的信息页http://hrbrmstr.github.io/metricsgraphics/上找不到任何东西,也找不到帮助手册中的任何内容。似乎使用颜色选项是针对直方图以外的每种图形类型解释的。

我不擅长的HTML/JavaScript和不知道还有什么尝试...

回答

1

你必须修改相应的直方图矩形类的CSS(查找类的名称在original CSS)。

一个简单的方法来做到这一点是添加以下代码到你UI定义:

tags$head(
    tags$style(HTML(" 
    .mg-histogram .mg-bar rect { 
     fill: <your_color>; 
     shape-rendering: auto; 
    } 

    .mg-histogram .mg-bar rect.active { 
     fill: <another_color>; 
    }"))) 

还有其他的方法来添加自定义CSS,看到here

这是一个完整的例子:

n <- 5 
library(metricsgraphics) 
library(shiny) 

# Define the UI 
ui <- bootstrapPage(
    tags$head(
    tags$style(HTML(" 
     .mg-histogram .mg-bar rect { 
      fill: #ff00ff; 
      shape-rendering: auto; 
     } 

     .mg-histogram .mg-bar rect.active { 
      fill: #00f0f0; 
     }"))), 
    numericInput('n', 'Number of obs', n), 
    metricsgraphicsOutput('plot') 
) 

server <- function(input, output) { 
    output$plot <- renderMetricsgraphics({ 
    mjs_plot(mtcars$mpg, format="count") %>% 
     mjs_histogram(bins = input$n) 
    }) 
} 

shinyApp(ui = ui, server = server)