`

Column

Topics in tSNE space

Column

Top 30 Features

---
title: "Correspondances during the Washington Presidency: topic summary"
output:
  flexdashboard::flex_dashboard:
    theme: yeti
    source_code: embed
    orientation: columns
    vertical_layout: fill
    
---
`


```{r include=FALSE}
library(tidyverse)
tsne0 <- readRDS('/home/jtimm/pCloudDrive/GitHub/data_sets/topics-ner/two_ds.rds')
tm_summary <- readRDS('/home/jtimm/pCloudDrive/GitHub/data_sets/topics-ner/tm_summary.rds')

x1 <- tm_summary$topic_word_dist %>%
  group_by(topic_id) %>%
  slice_max(order_by = beta, n = 30) %>%
  mutate(beta = round(beta, 3),
         feature = gsub('_', ' ', feature)) 

sd_points <- crosstalk::SharedData$new(tsne0, 
                                       group = "tm", 
                                       key = ~topic_id)
sd_features <- crosstalk::SharedData$new(x1, 
                                         group = "tm", 
                                         key = ~topic_id)
```



Column {data-width=550}
-------------------------------------

### Topics in tSNE space

```{r}
library(plotly)

p <- sd_points %>%
  
  ggplot2::ggplot(aes(x = X1, 
                      y = X2,
                      label = topic_id)) + 
  
  geom_hline(yintercept = 0, color = 'gray') +
  geom_vline(xintercept = 0, color = 'gray') +
  
  ggplot2::geom_point(size = 10, 
                      color = '#1a476f',
                      alpha = 0.5) +
  geom_text(size = 3) +
  theme_minimal() +
  theme(legend.position = 'none') 


#####
plotly::ggplotly(p) %>% 
  plotly::layout(showlegend = F,
                 autosize = T) %>%
  plotly::style(hoverinfo = 'none') %>%
  plotly::highlight(on = 'plotly_hover',
                    opacityDim = .75)
```





Column {data-width=450}
-------------------------------------
    
### Top 30 Features

```{r message=FALSE, warning=FALSE}
sd_features %>%
  
  DT::datatable(rownames = FALSE,
                options = list(dom = 't',
                               pageLength = 30,
                               autowidth = FALSE,
                               columnDefs = list(list(width = '300px',
                                                      targets = c(2))),
                               fixedColumns = TRUE
                               )) %>%
  
  DT::formatStyle(names(x1[,3]),
                  background = DT::styleColorBar(range(x1[,3]),
                                                 '#e76a53'),
                  backgroundSize = '80% 70%',
                  backgroundRepeat = 'no-repeat',
                  backgroundPosition = 'right')
```