0

I am trying to make a table that can display plots when the rows are click. Until now I can display a plot for the first row, but it only works the first time the row is click, but not for the second time.

ui <- fluidPage(
#Navbar structure for UI
navbarPage("Cars",
    tabPanel("Summary", 
        tabsetPanel(id="tabselected", type= "tabs", 
            tabPanel("Frequency plots",value=1),
                              tabPanel("Table", value=2)),
        sidebarLayout(
           sidebarPanel(
             conditionalPanel(condition = "input.tabselected==1" ), 
               conditionalPanel(condition = "input.tabselected==2")
                   ),
                    mainPanel(
                      conditionalPanel("input.tabselected == 2",
                              DT::dataTableOutput("SummaryTable")
                             )
                        )
                    )
               )
          )
  )

The problem is that the plot is displayed only one time when the row.child is shown, but after being hide, and show again the plots don't appear. Another problem is that I want to create a plot for each row, and that depends on the values of the selected row.
This is what I done so far. library('DT') library(shiny) server <- function(input, output, session) {

    output$SummaryTable<-DT::renderDataTable({
     datatable(
      cbind(' ' = '&oplus;',Cars=rownames(mtcars),  mtcars), escape = 1,
      options = list(
      columnDefs = list(
      list(visible = FALSE, targets = 0),
      list(orderable = FALSE, className = 'details-control', targets = 1)
    )
  ),
  callback = JS("
  table.column(1).nodes().to$().css({cursor: 'pointer'});
    var car = function(d){
                Shiny.setInputValue('name', d[0]);
       }
  var format = function(d) {
    return '<div id= \"container\" style=\"background-color:#eee;width:100%;height:400px; padding: .5em;\"> Model: ' +
            d[0] + ', mpg: ' + d[2] + ', cyl: ' + d[3] + '</div>';
  };
  table.on('click', 'td.details-control', function() {
    var td = $(this), row = table.row(td.closest('tr'));
    if (row.child.isShown()) {
      row.child.hide();
      td.html('&oplus;');
    } else {
      row.child(format(row.data())).show();
      car(row.data())
      td.html('&CircleMinus;');
         }
          });"
         ))
        })
       
            output$Boxplot<-renderPlot({
               input$name
               print(mtcars[input$name, ])
                  par(mar = c(0,0,0,0))
                  plot(mtcars[input$name, 1:3], main= input$name)
                }) 
         
         observeEvent(input$name,{      
              insertUI(
              selector="#container",
              where="beforeEnd",
              ui={  splitLayout(style = "border: 1px solid silver:",
               plotOutput(outputId = "Boxplot", width = "200px" ,height = "200px"))
              })
        })

}

enter image description here instead of text how can I display plots inside row tables when they are click,

enter image description here something like this but it is display only one time

enter image description here I tried this enter image description here

Ale m
  • 1
  • 1
  • Welcome to SO, Ale m! Please do not post (only) an image of code/data/errors: it breaks screen-readers and it cannot be copied or searched (ref: https://meta.stackoverflow.com/a/285557 and https://xkcd.com/2116/). Please include the code, console output, or data (e.g., `data.frame(...)` or the output from `dput(head(x))`) directly. – r2evans Aug 15 '22 at 22:05
  • It would also help a lot if you can make this question *reproducible*. This includes sample *unambiguous* data (e.g., `data.frame(x=...,y=...)` or the output from `dput(head(x))`) and intended output given that input. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Aug 15 '22 at 22:06

0 Answers0