LDAvis icon indicating copy to clipboard operation
LDAvis copied to clipboard

When put two ldavis output into one shinyapp, the second one cannot be reactive?

Open robinlish opened this issue 6 years ago • 3 comments

Thank you for your answers in advance!

The following is an example:

library(LDAvis) library(shiny)

server <- shinyServer(function(input, output, session) { output$myChart <- renderVis({ with(TwentyNewsgroups, createJSON(phi, theta, doc.length, vocab, term.frequency, R = input$nTerms))})

output$myChart1 <- renderVis({ with(TwentyNewsgroups, createJSON(phi, theta, doc.length, vocab, term.frequency, R = input$nTerms))}) })

ui <- shinyUI( fluidPage( sliderInput("nTerms", "Number of terms to display", min = 20, max = 40, value = 30), visOutput('myChart'), sliderInput("nTerms", "Number of terms to display", min = 20, max = 40, value = 30), visOutput('myChart1') ) )

shinyApp(ui = ui, server = server)

robinlish avatar Apr 29 '18 18:04 robinlish

I am also running into the exact same issues. I also ran the above code and noticed that the lambda slider for second output is linked to the first output only. Seems like Lambda slider component doesn't know which output has made the call.

harelhan avatar Sep 17 '18 10:09 harelhan

Hi @cpsievert Sorry to bug you. Just read on some other issues that issue of multiple outputs to Shiny has been fixed. Wanted to confirm you if that is indeed the case as I still am getting the same error.

Thanks Hitesh

harelhan avatar Sep 17 '18 12:09 harelhan

Fixed your slider id's:

library(LDAvis)
library(shiny)

ui <- shinyUI(
  fluidPage(
    sliderInput("nTerms1", "Number of terms to display", min = 20, max = 40, value = 30),
    visOutput('myChart1'),
    sliderInput("nTerms2", "Number of terms to display", min = 20, max = 40, value = 30),
    visOutput('myChart2')
  )
)

server <- shinyServer(function(input, output, session) {
  output$myChart1 <- renderVis({
    with(TwentyNewsgroups,
         createJSON(phi, theta, doc.length, vocab, term.frequency,
                    R = input$nTerms1))})
  
  output$myChart2 <- renderVis({
    with(TwentyNewsgroups,
         createJSON(phi, theta, doc.length, vocab, term.frequency,
                    R = input$nTerms2))})
})

shinyApp(ui = ui, server = server)

This is what happens: screen

ismirsehregal avatar Feb 19 '21 10:02 ismirsehregal