Невозможно связать sliderInput с selectInput для манипулирования кольцевой диаграммой - PullRequest
0 голосов
/ 05 июня 2019

Я пытался связать свой ползунок (с годами) с выпадающим списком selectInput (с коэффициентами свободы). Я получаю кольцевую диаграмму, но она распределена поровну. Я хочу выбрать параметры в раскрывающемся списке и изменить их тенденции с помощью ползунка. Я знаю, что что-то не так в выводе $ plot2 <- renderPlotly ({}), но не уверен, что это такое. </p>

global.r


df3<-  df1[, (names(df1) %in% c("year","region","pf_rol",   "pf_ss_homicide","pf_ss_disappearances_fatalities", "pf_ss_women_fgm", "pf_ss_women_inheritance", "pf_religion","pf_association_sport","pf_association_political",  "pf_expression_internet", "pf_identity_sex", "ef_legal_judicial", "ef_legal_military",  "ef_money_growth",  "ef_trade_tariffs_revenue", "ef_regulation_business_start","ef_regulation_business_bribes"
))]


netgraph <- df3 %>%
  group_by(year,region)%>%
  summarise_all(mean)

longdata <- gather(netgraph, key="freedom_factors", value="value", c("pf_rol",  "pf_ss_homicide","pf_ss_disappearances_fatalities", "pf_ss_women_fgm", "pf_ss_women_inheritance", "pf_religion","pf_association_sport","pf_association_political",  "pf_expression_internet", "pf_identity_sex", "ef_legal_judicial", "ef_legal_military",  "ef_money_growth",  "ef_trade_tariffs_revenue", "ef_regulation_business_start","ef_regulation_business_bribes"))

select_ops <- unique(longdata$freedom_factors)

server.r

shinyServer(function(input,output,session){

  years <- reactive({
   longdata %>%
     filter(year == input$yearslong)})

 selectfreedom <- reactive({
   longdata %>%
     filter(freedom_factors == input$variable)})

output$plot2 <- renderPlotly({
    donut <- selectfreedom() %>%
      group_by(region) %>%
      summarise(mean(value)) %>%
      plot_ly(labels = ~region, values = ~value) %>%
      add_pie(hole = 0.6) %>%
      layout(title = "Donut charts using Plotly",  showlegend = F,
             xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
             yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
    dput(longdata)
    })

})

ui.r

dashboardPage( 
    dashboardHeader(title = "Human Freedom Index", titleWidth = 300),
    dashboardSidebar(
      sliderInput("years","Select Year:",
                  min = min(df1$year),
                  max = max(df1$year),
                  value = min(df1$year),
                  step = 1),
selectInput("variable","Select Freedom Factor:",
                  c("Rule of Law"= "pf_rol",
                                  "Homicides Reported" = "pf_ss_homicide",
                                  "Women Dissapearances"="pf_ss_disappearances_violent",
                                  "Deaths by Terrorism"="pf_ss_disappearances_fatalities",
                                  "Female Mutiliation"= "pf_ss_women_fgm",
                                  "Women Inheritance" = "pf_ss_women_inheritance",
                                  "Freedom of Religion" = "pf_religion")),

 dashboardBody(
          fluidRow(
        box(plotlyOutput("plot2"), width=15, height=400)
      )
    )
  )

)

1 Ответ

0 голосов
/ 05 июня 2019

Я думаю, вам нужно это исправление -

selectfreedom <- reactive({
   years() %>%
     filter(freedom_factors == input$variable)})
...