Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R Plot.ly地图未在Shining应用程序中渲染_R_Plotly_Shiny - Fatal编程技术网

R Plot.ly地图未在Shining应用程序中渲染

R Plot.ly地图未在Shining应用程序中渲染,r,plotly,shiny,R,Plotly,Shiny,我很难获得一个闪亮的应用程序来渲染绘图仪地图 我收到的错误消息是:找不到对象“状态” plotly部分主要来自本教程: 不确定这是否与我的反应元素有关。反应元素很好地创建了ggplot图。感谢您的帮助 library(shiny) library(dplyr) library(plotly) state_tot <- read.csv("https://raw.githubusercontent.com/bkreis84/Data-604---Model/master/VIS/code

我很难获得一个闪亮的应用程序来渲染绘图仪地图

我收到的错误消息是:找不到对象“状态”

plotly部分主要来自本教程:

不确定这是否与我的反应元素有关。反应元素很好地创建了ggplot图。感谢您的帮助

library(shiny)
library(dplyr)
library(plotly)


state_tot <- read.csv("https://raw.githubusercontent.com/bkreis84/Data-604---Model/master/VIS/codeS.csv")


ui <- fluidPage(

   # Application title
   titlePanel("IRS Tax Data 2010 - 2015"),

   sidebarLayout(
      sidebarPanel(

        selectInput("var", 
                    label = "Select Variable:",
                    choices = c('Unemployment $ per Return' = 'UNEMP_COMP_PR', 
                                '% of Returns with Business Income' = 'PERC_BUSINESS_RETURN', 
                                '% with Real Estate Deduction' = 'PERC_RE', 
                                'AGI Per Return' = 'AGI_PR'),
                    selected = '% with Business Income'),


        sliderInput("yr",
                     "Select Year:",
                     min = 2010,
                     max = 2015,
                     value = 2015)



      ),


      # Show a plot of the generated distribution
      mainPanel(
        plotlyOutput("plot")



      )
  )
)


server <- function(input, output) {

  select <- reactive({
    year_sel <- input$yr

  })  

  df <- reactive({
    state_tot %>%
      filter(YEAR == select())
  })

  high <- reactive({ 
    switch(input$var,
           "PERC_BUSINESS_RETURN" = "green",
           "AGI_PR" = "green",
           "PERC_RE" = "green",
           "UNEMP_COMP_PR" = "red")
  })

  low <- reactive({ 
    switch(input$var,
           "PERC_BUSINESS_RETURN" = "red",
           "AGI_PR" = "red",
           "PERC_RE" = "red",
           "UNEMP_COMP_PR" = "green")
  })



  output$plot <- renderPlotly({
    g <- list(
      scope = 'usa',
      projection = list(type = 'albers usa'),
      lakecolor = toRGB('white')
    )
    plot_ly(z = df()[[input$var]], text = df()[[STATE]], locations = df()[[STATE]],
            type = 'choropleth', locationmode = 'USA-states') %>%
      layout(geo = g)
  })



} 

# Run the application 
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(dplyr)
图书馆(绘本)

state_tot错误在这一行:

plot_ly(z = df()[[input$var]], text = df()[[STATE]], locations = df()[[STATE]]
由于
STATE
没有被引用,因此您告诉R查找对象
STATE
中存储名称的列。如果要获取名为“STATE”的列,应引用该单词,因此:

plot_ly(z = df()[[input$var]], text = df()[["STATE"]], locations = df()[["STATE"]]

或者,将值“STATE”指定给对象
STATE
,该对象的状态为
STATE。非常感谢。