两个R版本的图表显示

时间:2016-10-30 13:37:58

标签: r highcharts shiny

我试图在两个R版本上运行下面的代码,并且没有相同的显示。我想显示一个值('10')只有一个类别('Feb'),这不适用于其中一个版本,在这里你可以看到输出比较:

enter image description here

以下是代码:

library("shiny")
library("highcharter")

data(citytemp)

ui <- fluidPage(
  h1("Highcharter EXAMPLE"),
  fluidRow(
    column(width = 8,
           highchartOutput("hcontainer",height = "500px")
    ),
    selectInput("option", label = "",  width = "100%",
                choices = c("Tokyo", "NY"))
  )
)

server <- function(input, output) {
  data <- citytemp[,c("month","tokyo","new_york")]
  data = data[data$month%in%c("Dec","Jan","Feb","Mar"),]
  choose_Option <- reactive({
    sort_option <- input$option
    if(sort_option=="Tokyo"){
      data = data[order(data$tokyo),]
    }
    else{
      data = data[order(data$new_york),]
    }
    return(data)
  })
  output$hcontainer <- renderHighchart({
    data = choose_Option()      
    data = data[data$month=="Feb",]
    chart <-  highchart() %>% 
      hc_chart(type = "bar") %>% 
      hc_title(text = "Monthly Average Temperature for main cities") %>% 
      hc_subtitle(text = "Source: WorldClimate.com") %>% 
      hc_xAxis(categories = data$month) %>% 
      hc_yAxis(title = list(text = "Temperature (C)"),stackLabels=list(enabled=FALSE))%>% 
      hc_plotOptions(
        series=list(stacking="normal"))

    hc <- chart %>% hc_add_series(yAxis=0,name="Tokyo",data = 10,colorByPoint=TRUE,dataLabels = list(enabled = TRUE) )

    return(hc)
  })
} 

shinyApp(ui = ui, server = server)

对于如何在版本3.2.0中更正我的显示,您有什么建议吗?谢谢你,最好的问候,Madzia

0 个答案:

没有答案