gpt4 book ai didi

r - 如何解决 "Error in tbl_vars(y) : argument "y"is missing, with no default"in Shiny?

转载 作者:搜寻专家 更新时间:2023-10-30 23:40:55 25 4
gpt4 key购买 nike

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

我已经编写了代码,但它不起作用。但是,几乎相同的示例运行良好。

这是我得到的:

      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 - 如何解决 "Error in tbl_vars(y) : argument "y"is missing, with no default"in Shiny?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35420491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com