Reputation: 147
I'm working on a shiny app, a part of the app displays a plotly pie chart
Is there a way to display a text instead of pie chart if the value in the pie chart is less than a particular number
I can think of is using an ifelse but I don't think its a feasible approach
output$plot<-renderPlotly({
plot_ly(selection, labels = ~Country, values = ~Freq, type = 'pie') %>%
layout(title = paste0("Percentage of patients from"," ",selection$Country[selection$Country!='Rest of the countries']," ","v/s rest of the countries"),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
})
The dataframe
Country Freq lon lat total q
India 4 78.96288 20.593684 299 1st Quantile(1-50 occurances
Rest of the countries 295 y y 299 y
Upvotes: 0
Views: 146
Reputation: 3760
Here is one way to do it:
library(shiny)
library(plotly)
shinyApp(
ui = fluidPage(selectInput("select","Select:", choices=unique(mtcars$cyl), selected = c(6)),
uiOutput("plot1")),
server = function(input, output) {
data <- reactive({
data <- mtcars[mtcars$cyl %in% input$select,]
})
output$plot1 <- renderUI({
if(input$select < 6){
print("Error")
}else{
plotlyOutput("plot2")
}
})
output$plot2 <- renderPlotly({
plot_ly(data(), x = ~mpg, y = ~hp, color = ~cyl)
})
}
)
I have just used another plot type from plotly
package (scatter plot) and mtcars
dataset as You have not provided reproducible example, neither the data. However the main concept is the same and there should not be any difference: i have used renderUI
for if...else...
statement which says if cyl is smaller then 6, print Error, else render plot.
In Your case instead of input$select
you should use the value which is decisive, and if i understood correctly it is Freq.
Upvotes: 1