3

How to render a DT::data.table and a wordcloud2::wordcloud2 in the mainPanel of a ShinyApp?

Here is a reproducible example. When I comment the wordcloud2 codes and adjust the code, the DT::data.table render normally.

# Only run examples in interactive R sessions
if (interactive()) {

    library(wordcloud2)

    n <- 1

    # Define UI
    ui <- fluidPage(

        # Application title
        titlePanel("titlePanel"),

        sidebarLayout(

            # Sidebar with a slider input
            sidebarPanel(
                textInput("user_input", h3("Field example"), 
                          value = "value"),
                numericInput('size', 'Size of wordcloud', n)
            ),

            # Show a plot of the generated distribution
            mainPanel(
                tabsetPanel(type = "tabs",
                            tabPanel("DT + wordcloud2", DTOutput('tbl'),
                                     wordcloud2Output('wordcloud2')),
                            tabPanel("Plot", plotOutput("plot")),
                            tabPanel("Summary",verbatimTextOutput("summary")),
                            tabPanel("about", tableOutput("table"))))))

    # Server logic
    server <- function(input, output) {

        output$tbl = renderDT(
            iris, options = list(lengthChange = FALSE))

        output$wordcloud2 <- renderWordcloud2({
            wordcloud2(demoFreq, size=input$size)})
    }

    # Complete app with UI and server components
    shinyApp(ui, server)
}

I want a wordcloud2 centered below the DT::data.table.

Thanks in advance.

  • 1
    Looks like any output with `wordcloud2Output` in the same tab does not work. Try to replace `DTOutput` with a `plotOutput`, the plot does not appear. So it seems this is not related to `DT`. – Stéphane Laurent Oct 18 '19 at 15:10
  • @Danilo Correa - please accept the answer below, as it provides a solution to your issue – Antoine Jan 13 '21 at 17:10

1 Answers1

2

This works with the latest Github version of wordcloud2. To install it:

remotes::install_github("Lchiffon/wordcloud2")
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225