- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
wordcloud2 包是否可以将 wordcloud 中任何单词的点击作为 Shiny 的点击事件返回,以便将其他对象(例如 bsModal)绑定(bind)到它?例如,在plotly中,这是通过生成一个可以从 Shiny session 中访问并保存事件数据(例如点击坐标)的对象来完成的( https://plot.ly/r/shinyapp-linked-click/ )。
在下面的示例中,我想将 bsModal 绑定(bind)到词云,以便显示用户单击的单词。
ui.R
library(shiny)
shinyUI(fluidPage(
mainPanel(
wordcloud2Output("wordcloud")
)
))
服务器.R
library(shiny)
library(wordcloud2)
library(tm)
shinyServer(function(input, output) {
words <- c ("1st", "2nd", "3rd", "4th", "5h", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th",
"21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th")
random_words <- sample(words, 500, replace = TRUE)
docs <- Corpus(VectorSource(random_words))
dtm <- TermDocumentMatrix(docs)
m <- as.matrix(dtm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
wordcloud_plot <- wordcloud2(data = d, size = 0.7, shuffle =FALSE, ellipticity = 1, minRotation = -pi/8, maxRotation = pi/8,
shape = 'circle')
output$wordcloud <- renderWordcloud2(wordcloud_plot)
})
最佳答案
是的,您可以通过向 Shiny 应用程序的 UI 添加几行 javascript 来解决此问题。
只需按如下方式修改您的 UI:
library(shiny)
shinyUI(fluidPage(
mainPanel(
wordcloud2Output("wordcloud"),
tags$script(HTML(
"$(document).on('click', '#canvas', function() {",
'word = document.getElementById("wcSpan").innerHTML;',
"Shiny.onInputChange('selected_word', word);",
"});"
))
)
))
此代码生成一个新的输入变量,您可以通过 Shiny 应用程序服务器端的 input$selected_word
访问该变量,并且可以使用该变量将词云与应用程序内的其他对象绑定(bind)。
由于它采用悬停函数的值,因此输入的格式将为word:freq
。您可以使用 gsub()
删除频率和冒号,如下所示:gsub(":.*","",isolate(input$selected_word))
希望对你有帮助!
关于r - 是否可以使用 wordcloud2 创建 Shiny 的点击事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44502965/
我正在尝试生成由一些硬编码字符串组成的 word_cloud 的 svg(截至目前,稍后将动态生成这些字符串)。下面是生成word_cloud的Python代码: from os import pat
我正在尝试从数据框中创建词云,其中有一列单词和一列代表它们各自的频率。我还下载了一张我想用作 mask 的图像,例如:cloud image 我无法让 wordcloud 适合 mask - 尽管遵循
我正在使用 twitter API 来产生情绪。我正在尝试根据推文生成词云。 这是我生成 wordcloud 的代码 wordcloud(clean.tweets, random.order=F,ma
我正在使用 Jupyter Notebook 并尝试构建词云。事实证明,枕头包装存在一些问题,互联网上充满了围绕它的讨论。我最初收到 DLL 错误。我尝试了很多不同的方法,不确定哪一种有效,但现在,我
我是 python 的新手,我正在使用 wordcloud pkg。 我根据字典 frequencies 中的频率生成了一个词云,key=words 和 values=frequencies of t
在词云中我有重复的词,我不明白为什么它们不一起计算,然后显示为一个词。 from wordcloud import WordCloud word_string = 'oh oh oh oh oh oh
在绘制词云图时发现有的字颜色为黄色导致看不清因此需要修改整个词云图的色调为冷色调 具体的来说 wordcloud中的color_func 参数使得我们能够自定义颜色函数
使用 wordcloud 时,我正在努力传播这些词功能。 data = tibble(Day = c("January", "February", "March" , "April", "May",
这似乎是一个简单的问题,但我似乎无法在任何地方找到答案。在 R {wordcloud} 包的 wordcloud 函数中,有一个可以输入的比例值。完整的文档(此处: https://cran.r-pr
我想用 R 构建一个词云(我已经使用 wordcloud 包做到了这一点),然后将特定单词涂上某种颜色。目前该函数的行为是根据频率给单词着色(这可能很有用),但单词大小已经做到了这一点,所以我想使用颜
我正在 python 中使用 wordcloud 库处理词云。 举个例子,我想从以下列表中制作一个词云: word_ls = ['orchards growers northern', 'apple
我正在创建一个词云,其中词的大小基于频率,但我希望将词的颜色映射到第三个变量(压力,这是与每个词相关的压力量,数值或连续变量)。 我尝试了以下方法,它只给了我两种不同的颜色(黄色和紫色),而我想要
我有以下 WordCloud。原始代码来自 Jason Davies D3-JavaScript-WordCloud Example。 https://github.com/jasondavies/d
我正在尝试以一种方式制作几个词云的子图/方面 赏心悦目。 问题: 我无法让基础 R 组合 wordcloud - 正确输出 使用 ggplot2 制作 wordcloud允许刻面但产生不令人满意的结果
我正在尝试在我的 GWT 项目中使用 d3-wordcloud( https://github.com/jasondavies/d3-cloud )。我将其包含在我的 .html 文件中: 其
我有以下功能作为 Shiny 应用程序(testapp)的一部分。它会生成默认选择的词云,但不会使用新选择进行更新。 ui.R library(shiny) shinyUI(fluidPage(
使用来自的描述功能 Online retail dataset , 我创建了一个词云。 descCorpus % rename(word=description, freq=sales) %>% wo
我正在尝试在此链接中制作有关电影类型的词云,但出现一些错误,名称“wordcloud”未定义即使包wordcloud 已安装。 有人可以帮我吗,python的版本是3.6.3。 import nump
我正在尝试使用这个 library 在 React 容器内创建一个词云.当通过数组 test 时,wordcloud 工作。 我想调用一个 api 来获取 wordcloud 的单词,然后将其传递给
我想突出显示用户点击的每个术语/单词,并为该特定术语/单词设置一个背景框。我正在使用点击功能,我可以访问和设置单词本身的颜色,但我无法设置这个单词的背景。我怎样才能做到这一点? 这是我的绘制函数: f
我是一名优秀的程序员,十分优秀!