我真的需要一些有用的帮助。
我已经编写了代码,但它没有用。然而,几乎相同的例子正在完美地运作。
这是我得到的:
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")
)))
)
)
server.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")
})
global.R
axis_vars <- c(
"Corruption Perception Index" = "cpi",
"Index Of Economic Freedom" = "icf",
"HDI" = "hdi",
"GINI" = "gini",
"Foreign Investments" = "finv",
"GDP per capita" = "gdp"
)
非常感谢!!!!
答案 0 :(得分:1)
刚遇到同样的问题,这个问题让我得到了解决方案。这里
all_c <- inner_join(corruption)
应该是
all_c <- some_other_table %>% inner_join(corruption)
因此错误消息来自dplyr,而不是来自闪亮。