Wordcloud不会在更新时使用新的输入
作为Shining app testapp的一部分,我有以下功能。它为默认选择生成单词cloud,但不随新选择更新 用户界面 服务器.RWordcloud不会在更新时使用新的输入,r,shiny,R,Shiny,作为Shining app testapp的一部分,我有以下功能。它为默认选择生成单词cloud,但不随新选择更新 用户界面 服务器.R library(shiny) library(rWordCloud) #require(devtools);install_github('adymimos/rWordCloud') library(data.table) source("helpers.R") df1<-readRDS("data/df1.rds") shinyServer(func
library(shiny)
library(rWordCloud) #require(devtools);install_github('adymimos/rWordCloud')
library(data.table)
source("helpers.R")
df1<-readRDS("data/df1.rds")
shinyServer(function(input, output) {
dataInput <- reactive({
isolate({
readydata(input$firm)
})
})
output$Plot1 <- renderd3Cloud({
data <- dataInput()
d3Cloud(text = data$indiv,size=data$Freq)
})
})
助手
readydata<-function(company){
data.frame(setDT(df1)[firm==company,list(Freq=.N),by=indiv][order(Freq,decreasing=TRUE)])
}
数据df1位于testapp内的数据文件夹内。数据结构如下:
df1<-structure(list(firm = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("a",
"b"), class = "factor"), indiv = structure(c(5L, 6L, 7L, 1L,
4L, 5L, 6L, 7L, 1L, 4L, 3L, 2L, 3L, 2L, 3L, 2L, 8L, 8L, 8L, 8L
), .Label = c("bello", "billow", "dillow", "fellow", "hello",
"kello", "nello", "tillow"), class = "factor")), .Names = c("firm",
"indiv"), row.names = c(NA, -20L), class = "data.frame")
另外,需要使用data.table,因为我正在聚合大量的组。wordcloud需要将其设置回dataframe 我认为你的问题在于:
dataInput <- reactive({
isolate({
readydata(input$firm)
})
})
我没有使用Render3Cloud-您可能需要使用datajavascript文件d3Cloud.js中有一个bug。我已经在rWordCloud的一个分叉处修复了它,并向adymimos提交了一个pull请求。实际的bug出现在htmlwidgets/d3Cloud.js的第59行 如果instance.lastValue!==未定义{ svg.remove; console.log'clearingsvg'; var svg=d3.selectel.appendsvg .attrclass,rWordCloud; instance.svg=svg; } 应该是
if ( instance.lastValue !== undefined) {
instance.svg.remove();
console.log('Clearing svg');
var svg = d3.select(el).append("svg")
.attr("class", "rWordCloud");
instance.svg = svg;
}
否则,您需要删除隔离,您可以将服务器.R代码简化为:
ShinyServerFunction输入、输出{
输出$Plot1谢谢。但是您提供的任何建议都不能解决我的问题。如果您能测试代码,我将不胜感激。我也无法让t工作。如果您为dataInput$indiv或dataInput$Freq添加文本输出,它们显然正在更新,但图形没有。我想知道这是否是rWordClud错误。再次感谢。我d尝试使用base r plot,它可能会像您所说的那样出现错误。我从您的github安装了该软件包,并且成功了。我将使用它,直到软件包维护人员修复该错误。非常感谢。@user227710它现在已合并到主分支中。感谢更新@Nick K,再次感谢您的帮助。
output$Plot1 <- renderd3Cloud({
data <- readydata(input$firm)
d3Cloud(text = data$indiv,size=data$Freq)
})
if ( instance.lastValue !== undefined) {
instance.svg.remove();
console.log('Clearing svg');
var svg = d3.select(el).append("svg")
.attr("class", "rWordCloud");
instance.svg = svg;
}