<commit_before>output$analyse_lda_fit <- renderUI(
  sidebarLayout(
    sidebarPanel(
      h5("Latent Dirichlet Allocation"),
      sliderInput("lda_ntopics", "Number of Topics", min=1, max=20, value=3),
      selectizeInput("lda_method", "Method", c("Gibbs", "VEM"), "Gibbs"),
      actionButton("lda_button_fit", "Fit"),
      render_helpfile("LDA Fit", "analyse/lda_fit.md")
    ),
    mainPanel(
      textOutput("analyse_lda_fit_")
    )
  )
)

output$analyse_lda_fit_ <- renderText({
  temp <- eventReactive(input$lda_button_fit, {
    withProgress(message='Fitting the model...', value=0,
    {
      runtime <- system.time({
        incProgress(0, message="Building to dtm...")
        DTM <- qdap::as.dtm(localstate$corpus)
        
        incProgress(1/2, message="Fitting the model...")
        localstate$lda_mdl <- topicmodels::LDA(DTM, k=input$lda_ntopics, method=input$lda_method)
        
        setProgress(1)
      })
    })
    
    paste("Fit a", input$lda_method, "LDA topic model in", round(runtime[3], roundlen), "seconds.")
  })
  
  temp()
})



output$analyse_lda_topics <- renderUI(
  sidebarLayout(
    sidebarPanel(
      h5("Latent Dirichlet Allocation"),
      sliderInput("lda_nterms", "Number of terms", min=5, max=50, value=10),
      render_helpfile("LDA Topics", "analyse/lda_topics.md")
    ),
    mainPanel(
      renderTable({
        if (!is.null(localstate$lda_mdl))
          topicmodels::terms(localstate$lda_mdl, input$lda_nterms)
        else
          stop("You must first fit a model in the 'Fit' tab!")
      })
    )
  )
)



output$analyse_lda_vis <- renderUI({
  sidebarLayout(
    sidebarPanel(
      h5("LDA Vis"),
      sliderInput("lda_vis_nterms", "Number of terms", min=5, max=50, value=10),
      render_helpfile("LDA Vis", "analyse/lda_vis.md")
    ),
    mainPanel(
      LDAvis::visOutput('analyse_lda_vis_')
    )
  )
})


output$analyse_lda_vis_ <- LDAvis::renderVis({
  withProgress(message='Preparing the data...', value=0,
  {
    post <- topicmodels::posterior(localstate$lda_mdl)
    setProgress(1/3)
    
    phi <- post$terms<commit_msg>minor<commit_after>output$analyse_lda_fit <- renderUI(
  sidebarLayout(
    sidebarPanel(
      h5("Latent Dirichlet Allocation"),
      sliderInput("lda_ntopics", "Number of Topics", min=1, max=20, value=3),
      selectizeInput("lda_method", "Method", c("Gibbs", "VEM"), "Gibbs"),
      actionButton("lda_button_fit", "Fit"),
      render_helpfile("LDA Fit", "analyse/lda_fit.md")
    ),
    mainPanel(
      textOutput("analyse_lda_fit_")
    )
  )
)

output$analyse_lda_fit_ <- renderText({
  temp <- eventReactive(input$lda_button_fit, {
    withProgress(message='Fitting the model...', value=0,
    {
      runtime <- system.time({
        incProgress(0, message="Building to dtm...")
        DTM <- qdap::as.dtm(localstate$corpus)
        
        incProgress(1/2, message="Fitting the model...")
        localstate$lda_mdl <- topicmodels::LDA(DTM, k=input$lda_ntopics, method=input$lda_method)
        
        setProgress(1)
      })
    })
    
    paste("Fit a", input$lda_method, "LDA topic model in", round(runtime[3], roundlen), "seconds.")
  })
  
  temp()
})



output$analyse_lda_topics <- renderUI(
  sidebarLayout(
    sidebarPanel(
      h5("Latent Dirichlet Allocation"),
      sliderInput("lda_nterms", "Number of terms", min=5, max=50, value=10),
      render_helpfile("LDA Topics", "analyse/lda_topics.md")
    ),
    mainPanel(
      renderTable({
        if (!is.null(localstate$lda_mdl))
          topicmodels::terms(localstate$lda_mdl, input$lda_nterms)
        else
          stop("You must first fit a model in the 'Fit' tab!")
      })
    )
  )
)



output$analyse_lda_vis <- renderUI({
  sidebarLayout(
    sidebarPanel(
      h5("LDA Vis"),
      sliderInput("lda_vis_nterms", "Number of terms", min=5, max=50, value=10),
      render_helpfile("LDA Vis", "analyse/lda_vis.md")
    ),
    mainPanel(
      LDAvis::visOutput('analyse_lda_vis_')
    )
  )
})

output$analyse_lda_vis_ <- LDAvis::renderVis({
  withProgress(message='Preparing the data...', value=0,
  {
    post <- topicmodels::posterior(localstate$lda_mdl)
    setProgress(1/3)
    
    phi <- post$terms
{'fraction_non_alphanumeric': 0.15008311564948942, 'fraction_numerical': 0.012348610781287106, 'mean_word_length': 3.1620553359683794, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4420918', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1510, 'n_words': 249}