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

时间:2017-04-30 20:52:40

标签: r shiny word-cloud

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

enter image description here

生成此代码的代码只是:

$result = array_intersect(...$strict);

2 个答案:

答案 0 :(得分:0)

删除框的一种方法是使用CSS样式将元素设置为不显示。这可以通过将此代码添加到UI的主体来完成:

tags$head(
      tags$style(HTML('div#wcLabel {display: none;}'))
    )

请注意,这也会导致滚动功能显示,当您将鼠标悬停在单词上时,该功能会显示字词的频率。就我而言,这是可取的。

答案 1 :(得分:0)

我通过使用此wordcloud2a()函数而不是常规的wordcloud2()

解决了问题
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
}

有关进一步的说明/讨论,请参见here