r - 如何计算出Shiny中的 "Error in tbl_vars(y) : argument "y“丢失,没有默认值”?

标签 r database ggplot2 shiny

我真的需要一些有用的帮助。

我已经写了代码,但它不起作用。然而,几乎相同的例子运行得很好。

这是我得到的:

      Warning: Error in tbl_vars: argument "y" is missing, with no default
      Stack trace (innermost first):
        45: tbl_vars
        44: as.vector
        43: base::intersect
        42: intersect.default
        41: intersect
        40: common_by
        39: inner_join.tbl_sql
        38: inner_join
         1: shiny::runApp
        Error in tbl_vars(y) : argument "y" is missing, with no default

我是 R 新手,尤其是 Shiny。 请帮忙。

这是代码和 dataset + 文件已附上。

ui.R

library(shiny)
library(ggvis)
library(datasets)

actionLink <- function(inputId, ...) {
tags$a(href='javascript:void',
     id=inputId,
     class='action-button',
     ...)
     }

     shinyUI(fluidPage(
     titlePanel("Corruption: Evidence from round the World" ),
     fluidRow(
     column(4,
     wellPanel(

textInput("country", "Country's Name"),


     selectInput("country", label = h5("Select the Country"), 
                 choices = list("All" = 1, "Choice 2" = 2,
                                "Choice 3" = 3, "All"), selected = 1),
     selectInput("country", label = h5("Select the Kind of Country's Association"), 
                 choices = list("EU" = 1, "BRICS" = 2,
                                "None" = 3), selected = 3),

       sliderInput("cpi", "Corruption Perception Index", 0, 100, step = 1, value = 27), # в скобках значения, которые горят для привлечения внимания к панели и объясняют, как ей пользоваться


       sliderInput("ief", "Index of Economic Freedom", 0, 100, step = 0.1, value = 51.9),                   


       sliderInput("hdi", "Human Development Index", 0, 1, step = 0.01, value = 0.80),


       sliderInput("gini", "GINI Index", 0, 100, step = 0.1, value = 41.6),                   

textInput("crate", label = h5("Credit Rating (S&P)"), value = "Enter rating..."))
  )
),
   fluidRow(
   column(4,  
   wellPanel(

selectInput("xvar", "X-axis variable", axis_vars, selected = "gdp"),
selectInput("yvar", "Y-axis variable", axis_vars, selected = "hdi")
  ),

    mainPanel(
    ggvisOutput("plot")

    )))
    )
    )

服务器.R

    library(shiny)
    library(ggvis)
    library(dplyr)
    if (FALSE) library(RSQLite)


    db <- src_sqlite("corruption.db")
    corruption <- tbl(db, "corruption")

    all_c <- inner_join(corruption)


    shinyServer(function(input, output, session) {

    corruption <- reactive({
    gdp <- input$gdp
    gni <- input$gni
    finv <- input$finv

c <- all_c %>%
  filter(
    CPI >= cpi,
    IndexOfEconomicFreedom >= icf,
    HDI >= hdi,
    GINI >= gini
  ) %>%
arrange(CPI)

  })

  vis <- reactive({

xvar_name <- names(axis_vars)[axis_vars == input$xvar]
yvar_name <- names(axis_vars)[axis_vars == input$yvar]

xvar <- prop("x", as.symbol(input$xvar))
yvar <- prop("y", as.symbol(input$yvar))

corruption %>%
  ggvis(x = xvar, y = yvar) %>%
  layer_points(size := 50, size.hover := 200,
               fillOpacity := 0.2, fillOpacity.hover := 0.5) %>%
  add_axis("x", title = xvar_name) %>%
  add_axis("y", title = yvar_name) %>%
  set_options(width = 500, height = 500)

    })

     vis %>% bind_shiny("plot")

    })

全局.R

      axis_vars <- c(
      "Corruption Perception Index" = "cpi",
      "Index Of Economic Freedom" = "icf",
      "HDI" = "hdi",
      "GINI" = "gini",
      "Foreign Investments" = "finv",
      "GDP per capita" = "gdp"
       )

非常感谢!!!!

最佳答案

刚刚遇到了同样的问题,这个问题引导我找到了解决方案。这里

all_c <- inner_join(corruption)

应该是这样的

all_c <- some_other_table %>% inner_join(corruption)

所以错误消息来自 dplyr 而不是来自shiny。

关于r - 如何计算出Shiny中的 "Error in tbl_vars(y) : argument "y“丢失,没有默认值”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35420491/

相关文章:

r - 降低栅格 R 分辨率的更快函数

sql - 如何检查数据库中是否存在 View ?

r - rmarkdown 中的 ggplotly 错误

r - 在 R 中创建一个函数,使所有 ggplot 组件更加透明

RMarkdown : how to get english error messages on a localised system

r - 在 MAC OS Sierra 中使用 R

android - 如何在普通表和 fts3 表之间创建触发器?

mysql - 具有额外信息的多对多关系

r - 如何在 R 中使用时间序列数据制作热图

r - 使用 sort() 和 cut() 将数值向量分段