0

I would like to have a popover and in the content to print a table(which in my case is named out). I have the table which looks like data.frame but when I run the command typeof(out), I get "list"

enter image description here

I have tried with the following code

addPopover(session=session, id="infocpbayestext", title="", 
         content=HTML(out), placement = "left",
         trigger = "hover", options = list(html = "true"))

And with

addPopover(session=session, id="infocpbayestext", title="", 
         content=HTML(build_infocpbayes_table(out)), placement = "left",
         trigger = "hover", options = list(html = "true"))

where build_infocpbayes_table is a function that tries to build a html table like this

"<table><tr><th>index</th><th>Date</th><th>Count</th><th>postprob</th></tr><tr> <td>..</td> <td>..</td> <td>...</td> <td>...</td> </tr></table>"

But although I build the correct string as above it does not appear in popover.

Any idea how could I do that?

Edit To give a better view of my code

shinyServer(function(input, output, session) {
output$infocpbayestext <- renderUI ({
  out<-structure(list(Date = c("2003-12", "2007-09", "2007-11"), Count =c(8721L,+ 31341L, 42948L), postprob = c(1, 1, 1)), row.names = c(174L,+ 219L,221L), class = "data.frame") 
addPopover(session=session, id="infocpbayestext", title="", content=HTML(build_infocpbayes_table(out)), placement = "left", trigger = "hover", options = list(html = "true"))
  return(HTML('<button type="button" class="btn btn-info">i</button>'))


})
build_infocpbayes_table <- function(data){
    html.table <- paste('<table style = "border: 1px solid black; padding: 1%; width: 300px;"><tr><th>index</th><th>Date</th><th>Count</th><th>postprob</th></tr><tr>',tags$td(HTML(paste0(rownames(data),collapse=""))),
                  tags$td(HTML(paste0(data$Date,collapse=""))),
                  tags$td(HTML(paste0(data$Count,collapse=""))),
                  tags$td(HTML(paste0(data$postprob,collapse=""))),
                '</tr></table>')
    return(html.table)
}})

shinyUI(uiOutput("infocpbayestext"))
vagelis
  • 326
  • 5
  • 18
  • hi, can you include a [reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? – bretauv Feb 04 '20 at 11:43
  • @bretauv I have added an edit, with more code but it is not reproducable because of the table "out" that I have posted as an image in the thread post – vagelis Feb 04 '20 at 12:16
  • why don't you use ```dput``` to generate the table ```out``` instead of putting an image? – bretauv Feb 04 '20 at 12:27
  • ok thank you I didn't know that, I am new in R. You could check now – vagelis Feb 04 '20 at 12:36
  • @bretauv any idea now with the updated code? – vagelis Feb 05 '20 at 13:11
  • you should look at the answers [here](https://stackoverflow.com/questions/33925430/shiny-plot-results-in-popup-window) and [here](https://stackoverflow.com/questions/45151436/shiny-datatable-popup-data-about-selected-row-in-a-new-window) – bretauv Feb 05 '20 at 13:17

0 Answers0