Closed Morais14 closed 7 years ago
Thanks Filipe,
WCtheme
is a function in dev version rather than CRAN.
plz devtools::install_github("lchiffon/wordcloud2")
And for character Encoding, could you please show me your sessionInfo()
Here's my sessioninfo():
**R version 3.4.0 (2017-04-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 LC_MONETARY=Portuguese_Brazil.1252 [4] LC_NUMERIC=C LC_TIME=Portuguese_Brazil.1252
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] wordcloud2_0.2.0 rCharts_0.4.5 devtools_1.13.2 tm_0.7-1 NLP_0.1-10 visNetwork_1.0.3
[7] shinyjs_0.9 highcharter_0.5.0 shinyBS_0.61 shinythemes_1.1.1 DT_0.2 formattable_0.2.0.1
[13] shiny_1.0.3 tidyr_0.6.3 stringr_1.2.0 dplyr_0.5.0 lubridate_1.6.0 leaflet_1.1.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.11 lattice_0.20-35 zoo_1.8-0 assertthat_0.2.0 rprojroot_1.2 digest_0.6.12
[7] psych_1.7.5 mime_0.5 slam_0.1-40 R6_2.2.1 plyr_1.8.4 backports_1.1.0
[13] evaluate_0.10 httr_1.2.1 rlang_0.1.1 lazyeval_0.2.0 curl_2.6 data.table_1.10.4
[19] miniUI_0.1.1 whisker_0.3-2 TTR_0.23-1 rmarkdown_1.5 foreign_0.8-67 htmlwidgets_0.8
[25] igraph_1.0.1 broom_0.4.2 compiler_3.4.0 httpuv_1.3.3 mnormt_1.5-5 htmltools_0.3.6
[31] tibble_1.3.3 withr_1.0.2 grid_3.4.0 nlme_3.1-131 jsonlite_1.5 xtable_1.8-2
[37] DBI_0.6-1 git2r_0.18.0 magrittr_1.5 rlist_0.4.6.1 quantmod_0.4-9 stringi_1.1.5
[43] reshape2_1.4.2 xts_0.9-7 tools_3.4.0 RJSONIO_1.3-0 markdown_0.8 purrr_0.2.2.2
[49] crosstalk_1.0.0 parallel_3.4.0 yaml_2.1.14 memoise_1.1.0 knitr_1.16**
Encoding
functiondocs <- c("текст один", "текст два")
docs <- enc2utf8(docs)
corp <- VCorpus(VectorSource(docs))
tdm <- TermDocumentMatrix(corp)
m = as.matrix(tdm)
dat = data.frame(rownames(m), rowSums(m))
wordcloud2(data = dat, gridSize=15, ellipticity=2)
prod_text <- c("ciência","stop","planning","educação","transformação","transformação","estático")
prod_text <- enc2utf8(prod_text)
prod_source <- VectorSource(x = prod_text)
corpus <- Corpus(x = prod_source)
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, stripWhitespace)
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, removeWords, stopwords("english"))
corpus <- tm_map(corpus, removeWords, stopwords("portuguese"))
corpus <- tm_map(corpus, removeWords, c("um","uma","da","do","de","uns","umas","das","dos","sobre","sob"))
dtm <- DocumentTermMatrix(x = corpus)
dtm2 <- as.matrix(dtm)
frequency <- colSums(dtm2)
frequency <- sort(frequency, decreasing=TRUE)
words <- names(frequency)
wordcloud2(data = data.frame(words, frequency), gridSize=15, ellipticity=2)
This code appers to me as:
It seems good in my Rstudio:
sessionInfo:
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] tm_0.6-2 NLP_0.1-9 wordcloud2_0.2.0
[4] ggplot2_2.2.1 shinydashboard_0.5.3 shiny_1.0.2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.10 plyr_1.8.4 tools_3.3.2
[4] digest_0.6.12 jsonlite_1.4 tibble_1.2
[7] gtable_0.2.0 lattice_0.20-34 png_0.1-7
[10] mapproj_1.2-4 yaml_2.1.14 parallel_3.3.2
[13] proto_1.0.0 stringr_1.1.0 RgoogleMaps_1.4.1
[16] htmlwidgets_0.8 maps_3.1.1 grid_3.3.2
[19] R6_2.2.0 jpeg_0.1-8 sp_1.2-4
[22] ggmap_2.6.1 reshape2_1.4.2 magrittr_1.5
[25] scales_0.4.1 htmltools_0.3.6 assertthat_0.1
[28] mime_0.5 xtable_1.8-2 geosphere_1.5-5
[31] colorspace_1.3-2 httpuv_1.3.3 stringi_1.1.2
[34] lazyeval_0.2.0 munsell_0.4.3 slam_0.1-40
[37] rjson_0.2.15
Maybe, try:
Sys.setlocale("LC_CTYPE","eng")
I figure out the problem after see your SessionInfo. It's the "tm" package in new versions after tm 0.6-2, more precisaly the Corpus function. Try update this package in your session and run the example again. Many thanks for your help and attention.
After update tm I see the bugs you met.
However, try to set the locale and remove the encoding codes:
library(tm)
library(wordcloud2)
Sys.setlocale("LC_CTYPE","eng")
prod_text <- c("ciência","stop","planning","educação","transformação","transformação","estático")
# prod_text <- enc2utf8(prod_text)
prod_source <- VectorSource(x = prod_text)
corpus <- Corpus(x = prod_source)
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, stripWhitespace)
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, removeWords, stopwords("english"))
corpus <- tm_map(corpus, removeWords, stopwords("portuguese"))
corpus <- tm_map(corpus, removeWords, c("um","uma","da","do","de","uns","umas","das","dos","sobre","sob"))
dtm <- DocumentTermMatrix(x = corpus)
dtm2 <- as.matrix(dtm)
frequency <- colSums(dtm2)
frequency <- sort(frequency, decreasing=TRUE)
words <- names(frequency)
wordcloud2(data = data.frame(words, frequency), gridSize=15, ellipticity=2)
It works in my Session but not in my shiny app. It seems shiny don't recognize
Sys.setlocale("LC_CTYPE","eng)
Can you write it in your shiny files?
Words like "educação" appears as "educaÃ".
library(shiny)
library(tm)
library(wordcloud2)
Sys.setlocale("LC_CTYPE","eng")
ui <- fluidPage(
titlePanel("Wordcloud"),
mainPanel(
wordcloud2Output("plot")
)
)
server <- function(input, output) {
output$plot <- renderWordcloud2({
prod_text <- c("Biopolyester from ricinoleic acid: Synthesis, characterization and its use as biopolymeric matrix for magnetic nanocomposites",
"Synthesis of carboxylate complexes and evaluation of their catalytic activities for polyesterification of castor oil (Ricinum communis) with terephthalic acid",
"Avaliação do tratamento físico-químico e dos resíduos de corantes produzidos em laboratório de microbiologia",
"Residual entropy and waterlike anomalies in the repulsive one dimensional lattice gas",
"Cosmologia, paisagem, lugar e o método fenomenológico: possíveis reflexões em uma cidade impactada por barragem",
"O Tratamento Quantitativo e sua Potencialidade para a Construção de Testes Psicométricos em Pesquisas de Educação Matemática. Perspectivas da Educação Matemática",
"Extrafloral nectary morphology and the role of environmental constraints in shaping its traits in a common Cerrado shrub (Maprounea brasiliensis A. St.-Hill: Euphorbiaceae)",
"ESPAÇO, TEMPO E NATUREZA: O PROCESSO E O MITO",
"Characterization of metal-biomass interactions in the lanthanum(III) biosorption on Sargassum sp. using SEM/EDX, FTIR, and XPS: Preliminary studies",
"Hardware and Software Co-design for the EKF Applied to the Mobile Robotics Localization Problem",
"Análise microbiológica e físico-química de bebida láctea pasteurizada, sem adição, comercializada no Distrito Federal",
"Evaluation of Petrifilm™ system compared with traditional methodology in count of indicators of sanitary-hygienic quality and pathogenic microorganisms in sheep milk",
"Formulations of Melia azedarach to Control Diabrotica speciosa (Germar) (Coleoptera: Chrysomelidae) Larvae in Corn and Plant Enhancement",
"Measuring the variability of the drosophilid assemblages associated with forests of the Brazilian savanna across temporal and spatial scales",
"Analisys of IT outsourcing contracts at the TCU (Federal Court of Accounts) and of the legislation that governs these contracts in the Brazilian Federal Public administration",
"A paisagem e a descoberta do mundo, em 'Campo geral', de Guimarães Rosa",
"Mirei e vi, o claro claramente: a magia poética da alegria e do amor, em Guimarães Rosa",
"Vibrational corrections to the second hyperpolarizabilities of AlnPn clusters",
"De la ville (au) texte: la littérature en tant qu'enquête urbaine et personnelle",
"Para além dos registros: histórias da APEB-Fr e da Psicologia segundo Sônia Alberti")
prod_source <- VectorSource(x = prod_text)
corpus <- Corpus(x = prod_source)
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, stripWhitespace)
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, removeWords, stopwords("english"))
corpus <- tm_map(corpus, removeWords, stopwords("portuguese"))
corpus <- tm_map(corpus, removeWords, c("um","uma","da","do","de","uns","umas","das","dos","sobre","sob"))
dtm <- DocumentTermMatrix(x = corpus)
dtm2 <- as.matrix(dtm)
frequency <- colSums(dtm2)
frequency <- sort(frequency, decreasing=TRUE)
words <- names(frequency)
wordcloud2(data = data.frame(words, frequency), gridSize=15, ellipticity=2)
})
}
shinyApp(ui = ui, server = server)
I think something happened in the tm package rather than wordcloud or shiny...
library(shiny)
library(tm)
library(wordcloud2)
Sys.setlocale("LC_CTYPE","eng")
ui <- fluidPage(
titlePanel("Wordcloud"),
mainPanel(
wordcloud2Output("plot")
)
)
server <- function(input, output) {
output$plot <- renderWordcloud2({
Sys.setlocale("LC_CTYPE","eng")
prod_text <- c("Biopolyester from ricinoleic acid: Synthesis, characterization and its use as biopolymeric matrix for magnetic nanocomposites",
"Synthesis of carboxylate complexes and evaluation of their catalytic activities for polyesterification of castor oil (Ricinum communis) with terephthalic acid",
"Avaliação do tratamento físico-químico e dos resíduos de corantes produzidos em laboratório de microbiologia",
"Residual entropy and waterlike anomalies in the repulsive one dimensional lattice gas",
"Cosmologia, paisagem, lugar e o método fenomenológico: possíveis reflexões em uma cidade impactada por barragem",
"O Tratamento Quantitativo e sua Potencialidade para a Construção de Testes Psicométricos em Pesquisas de Educação Matemática. Perspectivas da Educação Matemática",
"Extrafloral nectary morphology and the role of environmental constraints in shaping its traits in a common Cerrado shrub (Maprounea brasiliensis A. St.-Hill: Euphorbiaceae)",
"ESPAÇO, TEMPO E NATUREZA: O PROCESSO E O MITO",
"Characterization of metal-biomass interactions in the lanthanum(III) biosorption on Sargassum sp. using SEM/EDX, FTIR, and XPS: Preliminary studies",
"Hardware and Software Co-design for the EKF Applied to the Mobile Robotics Localization Problem",
"Análise microbiológica e físico-química de bebida láctea pasteurizada, sem adição, comercializada no Distrito Federal",
"Evaluation of Petrifilm™ system compared with traditional methodology in count of indicators of sanitary-hygienic quality and pathogenic microorganisms in sheep milk",
"Formulations of Melia azedarach to Control Diabrotica speciosa (Germar) (Coleoptera: Chrysomelidae) Larvae in Corn and Plant Enhancement",
"Measuring the variability of the drosophilid assemblages associated with forests of the Brazilian savanna across temporal and spatial scales",
"Analisys of IT outsourcing contracts at the TCU (Federal Court of Accounts) and of the legislation that governs these contracts in the Brazilian Federal Public administration",
"A paisagem e a descoberta do mundo, em 'Campo geral', de Guimarães Rosa",
"Mirei e vi, o claro claramente: a magia poética da alegria e do amor, em Guimarães Rosa",
"Vibrational corrections to the second hyperpolarizabilities of AlnPn clusters",
"De la ville (au) texte: la littérature en tant qu'enquête urbaine et personnelle",
"Para além dos registros: histórias da APEB-Fr e da Psicologia segundo Sônia Alberti")
# prod_text <- c("ciência","stop","planning","educação","transformação","transformação","estático")
# Encoding(prod_text) = 'latin1'
prod_source <- VectorSource(x = prod_text)
corpus <- Corpus(x = prod_source)
# corpus <- tm_map(corpus, content_transformer(tolower))
# corpus <- tm_map(corpus, removePunctuation)
# corpus <- tm_map(corpus, stripWhitespace)
# corpus <- tm_map(corpus, removeNumbers)
# corpus <- tm_map(corpus, removeWords, stopwords("english"))
# corpus <- tm_map(corpus, removeWords, stopwords("portuguese"))
# corpus <- tm_map(corpus, removeWords, c("um","uma","da","do","de","uns","umas","das","dos","sobre","sob"))
# dtm <- DocumentTermMatrix(x = corpus)
dtm2 <- as.matrix(dtm)
frequency <- colSums(dtm2)
frequency <- sort(frequency, decreasing=TRUE)
words <- names(frequency)
words[1:10]
wordcloud2(data = data.frame(words, frequency), gridSize=15, ellipticity=2)
})
}
shinyApp(ui = ui, server = server)
First of all congratulations to bring wordcloud to the R community.
I'm using wordcloud2 with this code in shiny:
**output$plot <- renderWordcloud2({
However i'm receiving this error message:
WCtheme: could not find function "WCtheme"
If a remove WCtheme everything works well, but with characeter enconding errors.
Before i was able to run this example without any errors.
Best regards!
Filipe