Advertisement
Guest User

Untitled

a guest
Nov 16th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. Eu estou querendo fazer um nuvem de palavras usando dados de uma tabela do postgresql,eu usei um exemplo como base que achei no site do Shiny R, mas nao estou conseguindo fazer oque eu quero.
  2. Nao consigo mudar qual a variável que vai servir como base da nuvem de palavras.Precisava que ao mudar o nome na seleção no "selectinput" a nuvem tambem deveria mudar a variavel que é usada.
  3.  
  4. Me ajudem por favor, eu preciso terminar isso para meu TCC.
  5.  
  6. Server.R
  7.  
  8. function(input, output, session) {
  9. # Define a reactive expression for the document term matrix
  10. terms <- reactive({
  11. # Change when the "update" button is pressed...
  12. input$update
  13. # ...but not for anything else
  14. isolate({
  15. withProgress({
  16. setProgress(message = "Processing corpus...")
  17. getTermMatrix(input$selection)
  18. })
  19. })
  20. })
  21.  
  22. # Make the wordcloud drawing predictable during a session
  23. wordcloud_rep <- repeatable(wordcloud)
  24.  
  25. output$plot <- renderPlot({
  26. v <- terms()
  27. wordcloud_rep(names(v), v, scale=c(4,0.5),
  28. min.freq = input$freq, max.words=input$max,
  29. colors=brewer.pal(8, "Dark2"))
  30. })
  31. }
  32.  
  33. Ui.R
  34. fluidPage(
  35. # Application title
  36. titlePanel("Word Cloud"),
  37.  
  38. sidebarLayout(
  39. # Sidebar with a slider and selection inputs
  40. sidebarPanel(
  41. selectInput("selection", "Choose a book:",
  42. choices = c("Forzza","Viana")),
  43. actionButton("update", "Change"),
  44. hr(),
  45. sliderInput("freq",
  46. "Minimum Frequency:",
  47. min = 1, max = 1000, value = 1),
  48. sliderInput("max",
  49. "Maximum Number of Words:",
  50. min = 1, max = 100, value = 100)
  51. ),
  52.  
  53. # Show Word Cloud
  54. mainPanel(
  55. tabsetPanel(type = "tabs",
  56. tabPanel("Plot", plotOutput("plot"))
  57.  
  58. )
  59. )
  60. )
  61. )
  62.  
  63. Global.r
  64. library(tm)
  65. library(wordcloud)
  66. library(memoise)
  67.  
  68. library(RPostgreSQL)
  69. con <- dbConnect(PostgreSQL(), user="postgres", password="123456",dbname="postgres")
  70. coletor1=dbGetQuery(con,"SELECT REPLACE(aux_coletprinc,' ','') aux_coletprinc from jabot.detacesso2 where aux_coletprinc ilike '%forz%a%'
  71. limit 10")
  72. coletor2=dbGetQuery(con,"SELECT REPLACE(aux_coletprinc,' ','') aux_coletprinc from jabot.detacesso2 where aux_coletprinc ilike '%vian%a%'
  73. limit 10")
  74.  
  75. dbDisconnect(con)
  76.  
  77. books <<- list("Forzza" ,
  78. "Viana" )
  79.  
  80.  
  81. # Using "memoise" to automatically cache the results
  82.  
  83.  
  84. getTermMatrix <- memoise(function(book) {
  85. # Careful not to let just any name slip in here; a
  86. # malicious user could manipulate this value.
  87.  
  88. text <- book
  89. myCorpus = Corpus(VectorSource(text))
  90. myCorpus = tm_map(myCorpus, content_transformer(tolower))
  91.  
  92. myDTM = TermDocumentMatrix(myCorpus,
  93. control = list(minWordLength = 1))
  94.  
  95. m = as.matrix(myDTM)
  96.  
  97. sort(rowSums(m), decreasing = TRUE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement