我刚开始发光,这一次给了我很大的困难。我尝试了几个建议,直到最后一次反应,但都没有效果。我不知道我做错了什么。
我尝试了%>% bind_shiny()和vis ({}),这两种方法都不起作用。如有任何建议,将不胜感激。
出现ui.R,但可视化没有,我也没有收到错误消息
server.R
library(shiny)
library(ggvis)
library(dplyr)
dataS <-read.csv("https://raw.githubusercontent.com/indianspice/IS608/master/Final%20Project/Data/shinydata.csv",
stringsAsFactors = FALSE)
function(input, output, session) {
#Filter breaches
breaches <- reactive({
records <- input$records
minyear <- input$year[1]
maxyear <- input$year[2]
# Apply filters
b <- dataS %>%
filter(
TotalRecords >= records,
Year >= minyear,
Year <= maxyear
) %>%
arrange(records)
#Filter by breach
if (input$breach != "All") {
breach <- paste0("%", input$breach, "%")
b <- b %>% filter(Breach %like% breach)
}
#Filter by company
if (!is.null(input$company) && input$company != "") {
company<- paste0("%", input$director, "%")
b <- b %>% filter(Company %like% company)
}
reactive({
xvar_name <- names(axis_vars)[axis_vars == input$year]
yvar_name <- names(axis_vars)[axis_vars == input$records]
xvar <- prop("x", as.symbol(input$xvar))
yvar <- prop("y", as.symbol(input$yvar))
breaches %>%
ggvis(x=xvar, y=yvar, stroke = ~breach) %>%
layer_points() %>%
add_axis("x", title = xvar_name) %>%
add_axis("y", title = yvar_name) %>%
add_legend("stroke", title = "Breach Type",
values = c("Hacking or Malware",
"Unintended Disclosure",
"Insider",
"Portable Device",
"Stationary Device",
"Unknown",
"Payment Card Fraud",
"Physical Loss")) %>%
scale_nominal("stroke", domain = c("Hacking",
"Unintended",
"Insider",
"Portable",
"Stationary",
"Unknown",
"Payment",
"Physical"),
range = c("red", "orange")) %>%
bind_shiny("ggvis", "ggvis_ui")
})
})
}ui.R
library(shiny)
library(ggvis)
dataS <- read.csv("https://raw.githubusercontent.com/indianspice/IS608/master/Final%20Project/Data/shinydata.csv",
stringsAsFactors = FALSE)
fluidPage(
titlePanel("Data Breaches in the United States"),
#fluidRow(
column(4,
h4("Filter Data"),
sliderInput("records", "Number of records breached",
min = 10,
max = 1000000,
value = 10000,
step = 500),
sliderInput("year", "Year breach reported",
sep = "",
min = 2005,
max = 2017,
value = c(2007, 2010)),
selectInput("breach", "Type of breach",
c("All",
"Hacking or Malware",
"Unintended Disclosure",
"Insider",
"Portable Device",
"Stationary Device",
"Unknown",
"Payment Card Fraud",
"Physical Loss")),
selectInput("organzation", "Select type of organization",
choices = unique(dataS$TypeofOrganization)),
selectInput("company", "Select company",
choices = unique(dataS$Company)
),
textInput("companyName", "Enter company name")
),
#),
mainPanel(
uiOutput("ggvis_ui"),
ggvisOutput("ggvis")
)
)数据
Company TypeofBreach TypeofOrganization TotalRecords Year
Bullitt Unintended Disclosure Educational Institutions 676 2009
Roane Portable Device Educational Institutions 14783 2009
Halifax Portable Device Healthcare Medical Provider 33000 2009
Suffolk Unintended Disclosure Educational Institutions 300 2009
Penrose Physical Loss Healthcare Medical Providers 175 2009发布于 2017-11-30 22:38:07
您是在一个反应性内部定义一个反应性,这是不好的。您应该使用breaches定义您的反应性(更改)数据reactive --这很好。然后,您应该使用来观察该数据的变化。
observe({
breaches() ... <do something>
...
%>% bind_shiny("ggvis", "ggvis_ui")
})最后,使用bind_shiny。关于如何做它的介绍,请参阅下面的最小示例(受ggvis帮助页的启发):
library(shiny)
runApp(list(
ui = fluidPage(
sliderInput("slider", "Select rows from mtcars to consider", min=1, max = nrow(mtcars), step = 1, value = c(1,10)),
ggvisOutput("p"),
uiOutput("p_ui")
),
server = function(input, output) {
# define the data according to some input
data <- reactive({
mtcars[ input$slider[1] : input$slider[2], ]
})
# observe changes in the data and update ggvis plot accordingly
observe({
data %>%
ggvis(~wt, ~mpg) %>%
layer_points() %>%
bind_shiny("p", "p_ui")
})
}
))

https://stackoverflow.com/questions/47565211
复制相似问题