R Shiny app. loop display word clouds and their labels -


following example https://gist.github.com/wch/5436415/ , this discussion , shiny gallery of wordcloud, managed make ui display multiple word cloud plots.

each of word cloud needs own title/label user knows each word cloud plot for. i'm not sure how achieve that. result ui rendered this:

label 1

label 2

label 3

world cloud 1

word cloud 2

word cloud 3

what want achieve having label displayed on top of corresponding word cloud; , display them adjacently. is:

label 1 | label 2 | label 3

plot 1 | plot 2 | plot 3

is there way iterate uioutput("plabels") , uioutput("plots") manipulate when display element?

thank in advance.

below code in server.r:

shinyserver(function(input, output, session) {         observe({     if (user$logged == true) {       output$obs <- renderui({           fixedpage(                         fixedrow(                     sliderinput("max", "slider", min = 1,  max = 100,  value = 20)               ),              # plots...               fixedrow(                 uioutput("labels"),                 uioutput("plots")               )         )       })        #### below make_plot r shiny online gallary ####       make_plot <- memoise(function(filename) {          text <- readlines(filename,encoding="utf-8")         mycorpus = corpus(vectorsource(text))         mycorpus = tm_map(mycorpus, content_transformer(tolower))         mycorpus = tm_map(mycorpus, removepunctuation)         mycorpus = tm_map(mycorpus, removenumbers)         mycorpus = tm_map(mycorpus, removewords,                           c(stopwords("smart"), "thy", "thou", "thee", "the", "and", "but"))          mydtm = termdocumentmatrix(mycorpus,control = list(minwordlength = 1))         m = as.matrix(mydtm)         sort(rowsums(m), decreasing = true)        })        pdata=list(0)       txt_dir <- "c:\\myfolder\\"             files <- list.files(path=txt_dir, pattern = ".txt")        ##labels       output$labels <- renderui({         label_output_list <- lapply(files, function(x) {            afile <- paste(txt_dir, x, sep="")            count_file <- count_file+1             my_i <- count_file           plotname <- paste("plot", my_i, sep="")           stitle <- paste("top words file ", gsub(".*[-]([^.]+)[.].*", "\\1", x))           output$label_msg <- rendertext({stitle})          })          taglist(label_output_list)       })#end output$labels <- renderui         #### word cloud plots ####       count_file <- 0       output$plots <- renderui({         plot_output_list <- lapply(files, function(x) {           afile <- paste(txt_dir, x, sep="")           count_file <- count_file+1            my_i <- count_file           pdata[[count_file]] <- make_plot(afile)            local({             plotname <- paste("plot", my_i, sep="")             wordcloud_rep <- repeatable(wordcloud)              output[[plotname]] <- renderplot({               terms <- reactive({                 # input[[slidername]]                 input$max                 isolate({                   withprogress({                     setprogress(message = "processing corpus...")                     pdata[[my_i]]                   })                 })               }) #end terms               v <- terms()               wordcloud_rep(names(v), v, scale=c(4,0.5),                             max.words=input$max,                             colors=brewer.pal(8, "dark2"))             })           })         })          taglist(plot_output_list)       })#end output$plots <-renderui     }   }) }) 

another thing don't understand notice have counter variable count_file auto increase 1 each time renders plot of txt file in specified directory, in console counter 1. never gets increased.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -