2017-07-31 68 views
0

我工作的一個閃亮的應用程序,該應用程序的一部分顯示plotly餅圖顯示文本,如果頻率小於給定數量的

是否有顯示文本,而不是餅圖,如果一種方法餅圖中的值小於某一特定數量的

我能想到的是使用ifelse的,但我不認爲這是一個可行的辦法

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)) 
    }) 

數據幀

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 
+1

什麼是'餅圖中的價值'? – Florian

+0

這些值是一個國家相對於世界其他地方的頻率的數值 –

回答

1

下面是做到這一點的一種方法:

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) 
}) 

    } 
) 

我剛纔用另一種圖表類型從plotly包(散點圖)和您沒有提供可重複的例子mtcars數據集,無論是數據。然而,主要概念是相同的,不應該有任何區別:我已經使用renderUIif...else...聲明,它說如果cyl小於6,打印錯誤,否則渲染情節。

在你的情況下,而不是input$select你應該使用決定性的值,如果我正確理解它是頻率。

相關問題