首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordcloud2闪亮的输出创建额外的小部件

wordcloud2闪亮的输出创建额外的小部件
EN

Stack Overflow用户
提问于 2017-04-30 20:52:40
回答 2查看 2.7K关注 0票数 5

使用wordcloud2 cran页面(https://cran.r-project.org/web/packages/wordcloud2/vignettes/wordcloud.html)上的示例,我在wordcloud下面得到了一个小的额外框。每当我使用wordcloud2包的r闪亮功能时,就会发生这种情况:

生成此代码的代码只是:

代码语言:javascript
复制
library(wordcloud2)
# Global variables can go here
n <- 1

# Define the UI
ui <- bootstrapPage(
  numericInput('size', 'Size of wordcloud', n),
  wordcloud2Output('wordcloud2')
)


# Define the server code
server <- function(input, output) {
  output$wordcloud2 <- renderWordcloud2({
    # wordcloud2(demoFreqC, size=input$size)
    wordcloud2(demoFreq, size=input$size)
  })
}
shinyApp(ui = ui, server = server)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-01 12:07:37

删除该框的一种方法是使用CSS样式将元素设置为“不显示”。只需将此代码添加到UI的主体中,就可以做到这一点:

代码语言:javascript
复制
tags$head(
      tags$style(HTML('div#wcLabel {display: none;}'))
    )

请注意,这也扼杀了滚动功能,该功能显示当您悬停在一个单词上时术语的频率。就我而言,这是可取的。

票数 1
EN

Stack Overflow用户

发布于 2020-07-08 08:57:09

我通过使用这个wordcloud2a()函数而不是普通的wordcloud2()来解决问题。

代码语言:javascript
复制
wordcloud2a <- function (data, size = 1, minSize = 0, gridSize = 0, fontFamily = "Segoe UI", 
          fontWeight = "bold", color = "random-dark", backgroundColor = "white", 
          minRotation = -pi/4, maxRotation = pi/4, shuffle = TRUE, 
          rotateRatio = 0.4, shape = "circle", ellipticity = 0.65, 
          widgetsize = NULL, figPath = NULL, hoverFunction = NULL) 
{
  if ("table" %in% class(data)) {
    dataOut = data.frame(name = names(data), freq = as.vector(data))
  }
  else {
    data = as.data.frame(data)
    dataOut = data[, 1:2]
    names(dataOut) = c("name", "freq")
  }
  if (!is.null(figPath)) {
    if (!file.exists(figPath)) {
      stop("cannot find fig in the figPath")
    }
    spPath = strsplit(figPath, "\\.")[[1]]
    len = length(spPath)
    figClass = spPath[len]
    if (!figClass %in% c("jpeg", "jpg", "png", "bmp", "gif")) {
      stop("file should be a jpeg, jpg, png, bmp or gif file!")
    }
    base64 = base64enc::base64encode(figPath)
    base64 = paste0("data:image/", figClass, ";base64,", 
                    base64)
  }
  else {
    base64 = NULL
  }
  weightFactor = size * 180/max(dataOut$freq)
  settings <- list(word = dataOut$name, freq = dataOut$freq, 
                   fontFamily = fontFamily, fontWeight = fontWeight, color = color, 
                   minSize = minSize, weightFactor = weightFactor, backgroundColor = backgroundColor, 
                   gridSize = gridSize, minRotation = minRotation, maxRotation = maxRotation, 
                   shuffle = shuffle, rotateRatio = rotateRatio, shape = shape, 
                   ellipticity = ellipticity, figBase64 = base64, hover = htmlwidgets::JS(hoverFunction))
  chart = htmlwidgets::createWidget("wordcloud2", settings, 
                                    width = widgetsize[1], height = widgetsize[2], sizingPolicy = htmlwidgets::sizingPolicy(viewer.padding = 0, 
                                                                                                                            browser.padding = 0, browser.fill = TRUE))
  chart
}

有关进一步解释/讨论,请参见这里

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43711197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档