作爲閃亮應用(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