2016-08-12 54 views
0

我試圖創建一個關於突尼斯選舉的閃亮的應用程序, 我把政黨作爲一個小部件,所以用戶可以選擇一個或多個政黨,應用程序會顯示各政黨的得票多少,我已經成功地選擇一個政黨的情況下,但是當用戶選擇一個以上的,它失敗:( 下述關於劇情的代碼R:閃亮的儀表板selectize輸入和情節

selectizeInput("parti", label = "Parti politique", choices= levels(data$Q99), selected = "Nidaa Tounes",multiple=TRUE) 

#server.R 
library(shiny) 
library(Rcmdr) 
library(ggplot2) 
library(ggalt) 
data <-  readXL("C:/Users/boti/Desktop/regression/bfinal.xlsx",rownames=FALSE, header=TRUE, na="NA", sheet="imp", stringsAsFactors=TRUE) 
shinyServer(function(input, output) { 
dataa<-reactive({as.data.frame(data)}) 

#Parti politique 
partii=reactive({ 
as.character(input$parti) 
}) 
output$plot1=renderPlot({ 
n=as.data.frame(table(dataa()[,95])) 
n$Var1[n$Var1==partii()] 

ggplot(n, aes(x =n$Var1[n$Var1==as.list(partii())] , y = n$Freq[n$Var1==as.list(partii())])) + geom_bar(stat = "identity", fill="Orange") + labs(title="Vote") +labs(x="Partis Politiques", y="Nombre de votes") 

}) 

}) 

回答

0

這例子使用mpg數據集來做我想做的事情,通過選擇輸入用戶選擇一個或多個製造商,並且barplot顯示c ARS選定廠家:

ui.R

library(shiny) 
    library(ggplot2) 
    shinyUI(fluidPage(
      titlePanel("Example"), 
      fluidRow(
        column(3, 
          selectizeInput("mpgSelect", 
              label = "Select manufacturer", 
              choices = levels(as.factor(mpg$manufacturer)), 
              selected = "audi", 
              multiple=TRUE))), 
      fluidRow(
        mainPanel(plotOutput('coolplot'),width = '40%')) 
    )) 

server.R

library(shiny) 
    library(ggplot2) 
    library(dplyr) 

    shinyServer(function(input, output) { 
      mpgSubset <- reactive({ 
        validate(
          need(input$mpgSelect != "", 'Please choose at least one feature.') 
        ) 
        filter(mpg, manufacturer %in% input$mpgSelect) 
      }) 
      output$coolplot<-renderPlot({ 
        gg <- ggplot(mpgSubset(), aes(x = manufacturer, y = ..count..)) 
        gg <- gg + geom_bar() 
        print(gg) 
      }) 
    }) 
+0

非常感謝你的先生它的工作:d – Asma