作为闪亮应用(testapp)的一部分,我有以下功能。它为默认选择生成词云,但不会使用新选择进行更新。Wordcloud不会使用Shiny中的新输入进行更新
ui.R
library(shiny)
shinyUI(fluidPage(
# Application title
headerPanel("Word Cloud"),
# Sidebar with selection inputs
sidebarPanel(width = 6,
selectInput("firm", label="Choose a firm:",
choices = c("a","b"),
selected = "a")
),
# Show Word Cloud
mainPanel(
d3CloudOutput("Plot1", width = "100%", height = 500)
)
))
server.R
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)
})
})
helpers.R
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")
p.S. data.table的使用是必要的,因为我汇集了大量的组。它需要重新设置为wordcloud的数据框。
我从你的github安装了软件包,它工作正常。我将使用它,直到软件包维护人员修复错误。非常感谢。 – user227710
@ user227710它现在被合并到主分支中。 –
感谢您的更新@Nick K,并再次为您提供帮助。 – user227710