hrbrmstr / metricsgraphics

:chart_with_upwards_trend: htmlwidget interface to the MetricsGraphics.js D3 chart library
http://hrbrmstr.github.io/metricsgraphics/
Other
132 stars 35 forks source link

Doesn't work with shiny navbarMenu page. #24

Open kismsu opened 9 years ago

kismsu commented 9 years ago

Hi, for some reasons if you put metricsgraphics on navbarMenu page, you can't access tabs. Here is a small example.

library(shiny)
library(metricsgraphics)

ui = shinyUI(navbarPage("Navbar!",
                        tabPanel("Home", h3("MetricsGraphics Example")),
                        navbarMenu("Plots",
                                   tabPanel("Plot1",
                                        metricsgraphicsOutput('mjs1')
                                    ),
                                    tabPanel("Plot2",
                                        metricsgraphicsOutput('mjs2')
                                    )
                        )
))

server = function(input, output) {

    mtcars %>%
        mjs_plot(x=wt, y=mpg, width=400, height=300) %>%
        mjs_point(color_accessor=carb, size_accessor=carb) %>%
        mjs_labs(x="Weight of Car", y="Miles per Gallon") -> m1

    set.seed(1492)
    stocks <- data.frame(
        time = as.Date('2009-01-01') + 0:9,
        X = rnorm(10, 0, 1),
        Y = rnorm(10, 0, 2),
        Z = rnorm(10, 0, 4))

    stocks %>%
        mjs_plot(x=time, y=X) %>%
        mjs_line() %>%
        mjs_add_line(Y) %>%
        mjs_add_line(Z) %>%
        mjs_axis_x(xax_format="date") %>%
        mjs_add_legend(legend=c("X", "Y", "Z")) -> m2

    output$mjs1 <- renderMetricsgraphics(m1)

    output$mjs2 <- renderMetricsgraphics(m2)

}

shinyApp(ui = ui, server = server)
Auburngrads commented 8 years ago

Second this. I have a similar app to what @kismsu has shown above. Changing metricsgraphicsOutput to plotOutput (while keeping everything else the same) allows me to pull down the navbarMenu options, although this obviously does not show the plot