简体   繁体   中英

Two wordcloud2 on the same shiny page

i'm trying to put two wordcloud2 in my shiny dahboard and the 2nd isn't showing

they are both in the body when i inspect the page

在此处输入图片说明

my script

library(wordcloud2)
library(shinydashboardd)
# Global variables can go here
n <- 1

# Define the UI
ui <- dashboardPage(
   box(wordcloud2Output('wordcloud2')),
   box(wordcloud2Output('wordcloud3'))
)


# Define the server code
server <- function(input, output) {
  output$wordcloud2 <- renderWordcloud2({
    wordcloud2(demoFreq)
  })

  output$wordcloud3 <- renderWordcloud2({
    wordcloud2(demoFreq)
  })

}
shinyApp(ui = ui, server = server)

edit: screenshoot when i use the answer script, there is no 2nd wordcloud

在此处输入图片说明

html output with both wordcloud div

<!DOCTYPE html>
<html>
<head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script type="application/shiny-singletons"></script>
  <script type="application/html-dependencies">json2[2014.02.04];jquery[1.12.4];shiny[1.2.0];htmlwidgets[1.3];wordcloud2[0.0.1];wordcloud2-binding[0.2.1];bootstrap[3.3.7]</script>
<script src="shared/json2-min.js"></script>
<script src="shared/jquery.min.js"></script>
<link href="shared/shiny.css" rel="stylesheet" />
<script src="shared/shiny.min.js"></script>
<script src="htmlwidgets-1.3/htmlwidgets.js"></script>
<link href="wordcloud2-0.0.1/wordcloud.css" rel="stylesheet" />
<script src="wordcloud2-0.0.1/wordcloud2-all.js"></script>
<script src="wordcloud2-0.0.1/hover.js"></script>
<script src="wordcloud2-binding-0.2.1/wordcloud2.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="shared/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<script src="shared/bootstrap/js/bootstrap.min.js"></script>
<script src="shared/bootstrap/shim/html5shiv.min.js"></script>
<script src="shared/bootstrap/shim/respond.min.js"></script>

</head>

<body>
  <div class="container-fluid">
    <div id="wordcloud2" style="width:100%; height:400px; " class="wordcloud2 html-widget html-widget-output"></div>
    <div id="wordcloud3" style="width:100%; height:400px; " class="wordcloud2 html-widget html-widget-output"></div>
  </div>
</body>

</html>

on this screenshoot there is no visilility; inherit on the 2nd wordcloud

在此处输入图片说明

I'm not running into any issues with this. I can't run your code because it has a few errors (you wrote shinydashboardd instead of shinydashboard , and your UI doesn't run because the dashboardPage() function can't take two boxes are parameters) but if I just fix those errors it works fine:

library(wordcloud2)
library(shiny)

ui <- fluidPage(
        wordcloud2Output('wordcloud2'),
        wordcloud2Output('wordcloud3')
)

server <- function(input, output) {
        output$wordcloud2 <- renderWordcloud2({
                wordcloud2(demoFreq)
        })

        output$wordcloud3 <- renderWordcloud2({
                wordcloud2(demoFreq)
        })
}

shinyApp(ui = ui, server = server)

(In the future, before posting a question with code, please make sure the code provided can run, unless of course the issue is with the code itself)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM