With htmlwidget, its become easy to bind d3 scripts to R. rWordCloud is one such package.
To install rWordCloud
Two main functions in rWordClouds are
source code - git hub
To install rWordCloud
require(devtools)
install_github('adymimos/rWordCloud')
Two main functions in rWordClouds are
- d3TextCloud - this function takes strings as input, and performs word count. Before word count, it does stemming, and stop word removal.
content <- c('R is a programming language and software environment for statistical computing and graphics open source','The R language is widely used among statisticians and data miners for developing statistical software and data analysis','Polls, surveys of data miners,and studies of scholarly literature databases show that R popularity has increased substantially in recent years','languages programming study open source, analysis') label <- c('a1','a2','a3','a4') d3TextCloud(content = content, label = label )
- d3Cloud - Function accepts word and its size
text <- c('d3','wordcloud','impressive','experiment','htmlwidgets','myfirstwidget') size <- c(25,20,13,9,6,5) df <- data.frame(text,size) d3Cloud(text = text, size = size)
- Shiny binding - information about clicked word from ui is send to server in shiny using the variable d3word.
ui.R
server.Rlibrary(shiny) library(rWordCloud) shinyUI(fluidPage( headerPanel("Interactive word cloud"), mainPanel( d3CloudOutput("plot", width = "100%", height = 500), h1(htmlOutput("text1"))) ))
library(shiny) library(rWordCloud) shinyServer(function(input, output, session) { output$plot <- renderd3Cloud({ d3Cloud(text = rownames(mtcars), size = mtcars$hp) }) output$text1 <- renderText({ if(!any(names(input)=='d3word')) return ("You havent clicked") paste ("You have clicked ",input$d3word) }) })
source code - git hub
Comments
Post a Comment