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

生成此代码的代码只是:
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)发布于 2017-05-01 12:07:37
删除该框的一种方法是使用CSS样式将元素设置为“不显示”。只需将此代码添加到UI的主体中,就可以做到这一点:
tags$head(
tags$style(HTML('div#wcLabel {display: none;}'))
)请注意,这也扼杀了滚动功能,该功能显示当您悬停在一个单词上时术语的频率。就我而言,这是可取的。
发布于 2020-07-08 08:57:09
我通过使用这个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
}有关进一步解释/讨论,请参见这里
https://stackoverflow.com/questions/43711197
复制相似问题