1

I am creating a Shiny dashboard application where for a menu item I have created two tab panels as shown in the below output.

Code:

library(shinydashboard)
library(shiny)
library(rAmCharts)
library(rCharts)
data(data_funnel)

body <- dashboardBody(
  #tags$style(type = "text/css", "#map {height: calc(100vh - 80px) !important;}"),
  tabItems(
    tabItem(tabName = "summary",
            tabsetPanel(
              tabPanel("tab1",  
                       fluidRow(
                         box(
                           title = "Box title", width = 5, status = "primary",
                           amChartsOutput(outputId = "amfunnel",width = "100%",height = "350px")
                         ),
                         box(
                           status = "warning", width = 5,
                           showOutput("stacked","nvd3")
                         ),
                         box(
                           status = "warning", width = 2, 
                           "Box Content"
                         )

                       )
              ),
              tabPanel("tab2",
                       fluidRow(
                         box(
                           title = "Box title", width = 7, status = "primary",
                           amChartsOutput(outputId = "ambarplot",width = "100%",height = "350px")
                         ),
                         box(
                           status = "warning", width = 3,
                           showOutput("piechart","nvd3")
                         ),
                         box(
                           status = "warning", width = 2, 
                           "Box Content"
                         )
                       )   
              )
            )  

      )
  )
)  
server <- function(input, output) {

  output$amfunnel <-  renderAmCharts({
    amFunnel(data = data_funnel, inverse = FALSE,margin_right = 0, margin_left = 190, label_side = "left")
  })

  output$stacked <- renderChart2({
    hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
    n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarHorizontalChart")
    n1$params$height = 390 
    n1$params$width = 450
    n1
  })

  output$ambarplot <- renderAmCharts({
    dataset <- data.frame(get(x = "USArrests", pos = "package:datasets"))
    amBarplot(y = c("Murder", "Assault", "UrbanPop", "Rape"), data = dataset, stack_type = "regular",horiz = TRUE,legend=TRUE)
  })

  output$piechart <- renderChart2({
    p1 <- nPlot(~ cyl, data = mtcars, type = 'pieChart')
    p1$params$height = 390 
    p1$params$width = 300
    p1
  })

}  

# We'll save it in a variable `ui` so that we can preview it in the console
ui <- dashboardPage(
  dashboardHeader(title = "Mixed layout"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Summary",tabName = "summary")
    )
  ),
  body
)

# Preview the UI in the console
shinyApp(ui = ui, server = server)

The output is as follows :

tab1

tab2

The problem I am facing is when I navigate from tab1 -> tab2 and again from tab2 -> tab1 , the box2 properties of tab1 are getting overlayed by the box2 properties of tab2.

Please let me know your thoughts on how to fix this issue.

Uwe
  • 41,420
  • 11
  • 90
  • 134
Kits228
  • 13
  • 4
  • @Uwe Block . Thanks for editing the question. Could you please help me if you know the solution for the above problem. – Kits228 Dec 25 '16 at 19:47
  • I'm no expert in that field but was able to reproduce the problem. In addition, I ran the app in Firefox 50 with developer tools turned on. The console showed `NS_ERROR_FAILURE` in `nv.d3.min-new.js` when switching back to `tab1`. Hopefully, someone more knowledgeable can asssist. – Uwe Dec 26 '16 at 09:59
  • There is an [answer by Clecocel](http://stackoverflow.com/a/37039818/3817004) to another question ["Formatting/aligning rCharts (nvd3) in shiny app"](http://stackoverflow.com/q/29384764/3817004). I followed the advice given there but it doesn't solve the issue. – Uwe Dec 26 '16 at 10:15
  • `RCharts` was a very innovative library when it came out. It still is in many ways. The problem is that it hasn't been updated in quite some time, i.e. the underlying libraries haven't been updated. While it has been the precursor for `htmlwidgets` it hasn't been re-implemented with them. The result is that often there are problems with shiny (i.e. conflicts with some of the `jquery` etc. libraries of shiny) and / or with some of the htmlwidgets widgets like `rAmChart`. The simplest solution for you is to try to re-implement your code using `rAmChart` or similar. It is sad: I love nvd3. – Enzo Dec 27 '16 at 17:38
  • Thanks for your feedback @Enzo. Yeah I have re-implemented my code using rAmCharts and its working fine now without any issues. – Kits228 Dec 28 '16 at 04:03

0 Answers0