情节没有在Shiny R应用程序中显示

时间:2015-10-15 16:01:20

标签: r plot ggplot2 shiny

我有一个闪亮的应用程序。

我附加的部分数据框: https://www.dropbox.com/s/nvg3cj6u37l2rc8/example.csv?dl=0

我有代码:

Ui.R

library(shiny)
library(htmlwidgets)
library(D3TableFilter)
library(shinydashboard)

shinyUI(navbarPage("App",


                   tabPanel("Compare",
                            fluidRow(
                              column(4, selectInput("statesearch", "Region: ",
                                                    c('region1', 'region2', 'region3', 'region4', 'region5',  'region6', 'region7', 'region8', 'region9', 'region10', 'region11', 'region12'),
                                                    selected="All"),

                                     br()
                              ),

                              column(8,
                                     plotOutput("g2", width = "100%"))
                            )

                   )


)
)

Server.R

require(ggplot2)
require(shiny)



# Load the dataset

loadData <- function() {

  comp <- read.csv("./data/comp.csv")
  return(df)
}




# Plot comparision
getCompare<- function(df, reaction){
  comp <- df[[4]]
  state = reaction$state
  indices <- which(comp$State == state)
  new_df <- df[indices, ]
  g2 <- ggplot(new_df, aes(x=Year, y= Percent, fill= Name)) +
    geom_bar(aes(width=.65), stat="identity")
  return(g2)
}

##### GLOBAL OBJECTS #####

# Shared data
globalData <- loadData()

##### SHINY SERVER #####
# Create shiny server.
shinyServer(function(input, output) {
  cat("Press \"ESC\" to exit...\n")
  # Copy the data frame 
  localFrame <- globalData


  getReaction3 <- reactive({
    return(list(
      state = input$statesearch
    ))
  }) # getReaction3


  # Output Plots.

  output$g2 <- renderPlot({print(getGraph(localFrame, getReaction3()))},width=1000,height=600) # output map
}) # shinyServer

我在运行代码时遇到情节显示问题。

我明白了:

  

is.na(e2)中的警告:is.na()应用于非(列表或向量)   在eval中键入'NULL'错误(替换(expr),envir,enclos):
  长度不正确(0),期待:547565

如果我替换filter(State == "region1")并在不同的脚本中运行一步一步的代码,那么一切都很好。 你能帮忙吗? 此致

0 个答案:

没有答案