I have two sample dataframes given below
library(shiny)
df1 <- data.frame(words = c("bat", "vat","cat","mat"), count = c(3420, 2098, 2003, 1501), words_count = c("bat (3420)","vat (2098)", "cat (2003)", "mat (1501)"), stringsAsFactors = FALSE)
df2 <- data.frame(class = c("A","B","C","D"), bat = c(10,0,30,20), vat = c(0,0,10,30), cat = c(20,30,0,10), mat = c(20,20,0,0), stringsAsFactors = FALSE)
Using the code below I want to extract the column name from drop down menu (made from df1) and use the extracted value to plot the bar graph in plotly using extracted value as column in df2. I am doing this is Rmd.
inputPanel(
selectInput("words", label = "Choose the word",
choices = df1$words_count,
selected = df1$words_count[1], width = '100%')
)
renderPlot({
# Extract the word from drop down
col_word <- df1 %>% filter(words_count == input$words) %>% pull(words)
plot_ly(df2, x = ~category, y = ~col_word, type = 'bar') %>%
layout(yaxis = list(title = 'Count'), xaxis = list(title = ""))
})
I get no output. I have tried a couple of things like get(col_word) however, it does not work.