Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedding d3output in Shiny Dashboard #61

Open
apoorv2210 opened this issue Apr 11, 2019 · 2 comments
Open

Embedding d3output in Shiny Dashboard #61

apoorv2210 opened this issue Apr 11, 2019 · 2 comments

Comments

@apoorv2210
Copy link

apoorv2210 commented Apr 11, 2019

I am working on some visualization using the r2d3 package and integrating the d3output on a Shiny Dashboard.

While I completed what I thought would be the difficult chunks of work, I am stuck at a rather trivial stage.

After generating the d3output, I am not able to restrict it inside a box within a dashboardPage - it is covering the complete width of the page (including sidebarPanel) and eclipsing the dashboard, while the box where it is declared to appear is displaying as an empty box.

Please let me know what I might be missing out on here. I have spent a lot of time on this but have not been able to crack this one.

Please find a snip of the dashboard to better understand the issue.
snip

Here is how I'm writing the code:

library(shiny)
library(r2d3)
library(data.tree)


ui <- dashboardPage(
  
  ##========================== Dashboard Header ==========================##  
  
  dashboardHeader(title = 'R2D3 Dashboard',titleWidth = 280
                  # tags$li(class = "dropdown",
                  #         tags$a(tags$img(height = "20px", alt="Logo", src="logo.png", background = "white")))
  ),
  
  ##========================== Side Panel (Filters & Selections) ==========================##
  dashboardSidebar( width=280,
                    
                    sidebarMenu(
                      
                      menuItem(text=strong('Tree'),
                               newtab=FALSE,
                               icon=NULL,
                               tabName="tab_11",
                               startExpanded=TRUE
                      )
                    )
  ),
  
  dashboardBody(
    fluidPage(theme="style.css",
      

      verticalLayout(
        box(width=12,d3Output("d5"),value = TRUE)),
      
      verticalLayout(
        box(width=12,verbatimTextOutput("selected"),value = TRUE))
      
    )

  )
)

# ui <- dashboardPage(
#   titlePanel("R2D3 sample"),
#   sidebarLayout(
#     sidebarPanel(),
#     mainPanel(
#       verbatimTextOutput("selected"),
#       d3Output("d5")
#     )
#   )
# )

server <- function(input, output) {
  output$d5 <- renderD3({
    r2d3(
      NULL,
      script = "examples/tree.js", d3_version = 3,
      dependencies = "style.css"
    )
  })
  
  output$selected <- renderText({
    input$bar_clicked
  })
}

shinyApp(ui = ui, server = server)

Due to the confidential nature of the data, I can't share the supporting files. Pardon me for the partial content.

--
Thanks & Regards,
Apoorv Mehrotra

@mpkrass7
Copy link

mpkrass7 commented Oct 23, 2019

I was having the same problem. I think if you add options(r2d3.shadow = FALSE) to your r2d3() call, you'll be able to render your viz in the correct place
https://rstudio.github.io/r2d3/reference/r2d3.html

Hope it helps!

@alptaciroglu
Copy link

I am experiencing the same issue. I tried @mpkrass7's options tip but did not do the trick for me. I would really appreciate any input.

I asked for help in this Github page with a minimally reproducible code attached.

nstrayer/js4shiny_r2d3#1 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants