I am trying to plot the common phrases just before a crash versus its frequency. Instead of creating a new slider, I decided to use a slider that is already there on the same page. Since in the chart I only have 17 bars, I want that if the slider input is 17 or less it plot the corresponding number of bars from the slider else it should plot 17 bars.
My UI Code is:
tabPanel("Word Cloud",
sidebarLayout(
sidebarPanel( tags$div(
tags$strong("About Word Cloud"), br(),
"A word cloud (weighted list in visual design) is a novelty visual representation of text data. It depicts the words which occured more frequently in the aircrash summary. The importance of each tag is shown with font size and color. The user has the ability to change the number of words they want to see in the word cloud by adjusting the slider below.",
br(), br()),
sliderInput("numberInput2", "Maximum Number of Words:", min=1, max=105,
value=35)
),
mainPanel(plotOutput("WordCloudPlot"),
br(),
plotlyOutput("WordCloudBarPlot"),
br(),
plotlyOutput("AircrashPhrases")
)
)
)
My server code is:
d8<- reactive({
req(input$numberInput2)
if (input$numberInput2 <= 17) {
common_phrases %>%
dplyr::top_n(input$numberInput2)
}
else {
common_phrases %>%
dplyr::top_n(17)
}
})
output$AircrashPhrases <-renderPlotly({
a8 <- ggplot(d8(), aes(x=reorder(word, -frequency), y=frequency))+
geom_bar(stat="identity", fill='steelblue')+theme_bw()+
theme(plot.title = element_text(color = "black", size = 20, face = "bold", hjust = 0.5),
axis.title.x =element_text(color = "black", size = 14, face = "bold", hjust = 0.5),
axis.title.y = element_text(color = "black", size = 14, face = "bold", hjust = 0.5))+
labs(y = "Frequency",x="Words",title = "Word Cloud Frequency")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplotly(a8, source = "select", tooltip = "frequency")
})
The error that I'm getting for my second plot (output$AircrashPhrases) is "invalid argument to unary operator". Please let me know how I can fix it.
Thanks