Select columname through selectinput in shiny appliaction - r

I'm trying to build a shiny app, it is good to go but I am trying to put a column from my dataframe in selectinput, but so far didn't found a solution. I have a column with 505 factors, called AAPL, AAL, etc.. I want these factors in my selectinput, so that you can choose from these 505 factors, This is my code right now, and the column name that I'm trying to get in selectinput is bcl-data$Name.
library(shiny)
library(tidyverse)
library(shinythemes)
library(ggplot2)
library(dplyr)
bcl <- read.csv("bcl-data.csv", stringsAsFactors = FALSE)
# Define UI for application that draws a histogram
ui <- fluidPage(theme = shinytheme("darkly"),
# Application title
titlePanel("Overzicht S&P 500 Aandelen"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "priceInput", label = "close", min = 0, max = 2050, value = c(0,300), pre = "$"),
selectInput(inputId = "typeInput", label = "Name", choices = (bcl-data$Name)),
dateRangeInput(inputId = "dateInput",
label = "date",
start = "2013/02/08",
end = "2013/03/08",
format = "yy/mm/dd")
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("Plot")),
tabPanel("Datatable", tableOutput("Datatable"))
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$Plot <- renderPlot({
filtered <- bcl %>%
filter(close >= input$priceInput[1]) %>%
filter(close <= input$priceInput[2]) %>%
filter(date >= input$dateInput[1] & date <= input$dateInput[2]) %>%
filter(bcl-data$Name == input$typeInput)
filtered
ggplot(filtered, aes(x = date, y = close, color = Name)) +
geom_point()
})
output$Datatable <- renderTable({
filtered <-
bcl %>%
filter(close >= input$priceInput[1]) %>%
filter(close <= input$priceInput[2]) %>%
filter(date >= input$dateInput[1] & date <= input$dateInput[2]) %>%
filter(bcl-data$Name == input$typeInput)
filtered
})
}
# Run the application
shinyApp(ui = ui, server = server)

Comment from above: I think you're error is with bcl-data$Name. While bcl-data.csv is the file you loaded, you saved it as the object bcl - meaning it should simply be bcl$Name. selectInput(inputId = "typeInput", label = "Name", choices = bcl$Name) In your filters, you can also simply have filter(Name == because you're already feeding the bcl data/object through the pipe.
To make sure we remove duplicate values, we can include unique.
Here's what I think should work (cannot test because no data).
library(shiny)
library(tidyverse)
library(shinythemes)
library(ggplot2)
library(dplyr)
bcl <- read.csv("bcl-data.csv", stringsAsFactors = FALSE)
# Define UI for application that draws a histogram
ui <- fluidPage(theme = shinytheme("darkly"),
# Application title
titlePanel("Overzicht S&P 500 Aandelen"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "priceInput", label = "close", min = 0, max = 2050, value = c(0,300), pre = "$"),
selectInput(inputId = "typeInput", label = "Name", choices = unique(bcl$Name)),
dateRangeInput(inputId = "dateInput",
label = "date",
start = "2013/02/08",
end = "2013/03/08",
format = "yy/mm/dd")
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("Plot")),
tabPanel("Datatable", tableOutput("Datatable"))
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$Plot <- renderPlot({
filtered <- bcl %>%
filter(close >= input$priceInput[1]) %>%
filter(close <= input$priceInput[2]) %>%
filter(date >= input$dateInput[1] & date <= input$dateInput[2]) %>%
filter(Name == input$typeInput)
filtered
ggplot(filtered, aes(x = date, y = close, color = Name)) +
geom_point()
})
output$Datatable <- renderTable({
filtered <-
bcl %>%
filter(close >= input$priceInput[1]) %>%
filter(close <= input$priceInput[2]) %>%
filter(date >= input$dateInput[1] & date <= input$dateInput[2]) %>%
filter(Name == input$typeInput)
filtered
})
}
# Run the application
shinyApp(ui = ui, server = server)

Related

How avoid "invalid (NULL) left side of assignment" error in R Shiny app?

I have a dataset and want to create an R Shiny app with if condition (based on RadioButton).
Additionally, after filtering my initial dataset, I want to replace all 2 values in Quantity column to 200 (Yes, it it possible to do it outside the server(), but in my case, it is necessary to do it inside).
I always get error here sales_by_mfr()$Quantity <- reactive(ifelse(sales_by_mfr()$Quantity == 2,200,sales_by_mfr()$Quantity))
Additionally, I tried to replace all 2 values in my dataset with sales_by_mfr()[sales_by_mfr() == 2] <- reactive({200}) , however got the same error.
Could you help to find a way to avoid "invalid (NULL) left side of assignment" error inside this code?
library(dplyr)
library(shiny)
data <- MASS::Cars93[18:47, ] %>%
mutate(ID = as.character(18:47), Date = seq(as.Date("2019-01-01"), by = "day", length.out = 30)) %>%
select(ID, Date, Manufacturer, Model, Type, Price)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
#sliderInput
radioButtons("dist", "Data:",
c("The most recent" = "most_recent",
"Historical" = "historical"))
),
# plot graphs
mainPanel(tabsetPanel(
tabPanel("Plot",
h3(helpText("Nordpool prices")),
#plotOutput("plot"),
reactableOutput("table")
#h3(helpText("Descr.statistics")),
#verbatimTextOutput("Descr.stat.price")
)
)
))
)
server <- function(input, output, session) {
sales_by_mfr<-reactive({
if (input$dist == "most_recent"){
data %>%
filter(Manufacturer %in% c("Chevrolet","Hyundai","Honda")) %>% group_by( Manufacturer) %>%
summarize(Quantity = n(), Sales = sum(Price))
}else{
data %>%
group_by( Manufacturer) %>%
summarize(Quantity = n(), Sales = sum(Price))
}
})
sales_by_mfr()$Quantity <- reactive(ifelse(sales_by_mfr()$Quantity == 2,200,sales_by_mfr()$Quantity))
#sales_by_mfr()[sales_by_mfr() == 2] <- reactive({200})
#Create columns in two rows (1-dat,2-diffs)
output$table <- renderReactable({
reactable(
sales_by_mfr(),#
# columns = columns(),columnGroups = columnGroups()
#defaultColDef = colDef(minWidth = 222,vAlign = "center"),
#defaultColDef = colDef(vAlign = "center", headerVAlign = "bottom"),
# Set a maximum width on the table:
#style = list(maxWidth = 650),
# Or a fixed width:
#width = 650,
)
})
}
shinyApp(ui = ui, server = server)
Try this
library(MASS)
library(reactable)
data <- MASS::Cars93[18:47, ] %>%
mutate(ID = as.character(18:47), Date = seq(as.Date("2019-01-01"), by = "day", length.out = 30)) %>%
dplyr::select(ID, Date, Manufacturer, Model, Type, Price)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
#sliderInput
radioButtons("dist", "Data:",
c("The most recent" = "most_recent",
"Historical" = "historical"))
),
# plot graphs
mainPanel(tabsetPanel(
tabPanel("Plot",
h3(helpText("Nordpool prices")),
#plotOutput("plot"),
reactableOutput("table")
#h3(helpText("Descr.statistics")),
#verbatimTextOutput("Descr.stat.price")
)
)
))
)
server <- function(input, output, session) {
sales_by_mfr<-reactive({
if (input$dist == "most_recent"){
data %>%
filter(Manufacturer %in% c("Chevrolet","Hyundai","Honda")) %>% group_by( Manufacturer) %>%
summarize(Quantity = n(), Sales = sum(Price))
}else{
data %>%
group_by( Manufacturer) %>%
summarize(Quantity = n(), Sales = sum(Price))
}
ifelse(data$Quantity == 2,200,data$Quantity)
data
})
#sales_by_mfr()$Quantity <- reactive(ifelse(sales_by_mfr()$Quantity == 2,200,sales_by_mfr()$Quantity))
#sales_by_mfr()[sales_by_mfr() == 2] <- reactive({200})
#Create columns in two rows (1-dat,2-diffs)
output$table <- renderReactable({
reactable(
sales_by_mfr(),#
# columns = columns(),columnGroups = columnGroups()
#defaultColDef = colDef(minWidth = 222,vAlign = "center"),
#defaultColDef = colDef(vAlign = "center", headerVAlign = "bottom"),
# Set a maximum width on the table:
#style = list(maxWidth = 650),
# Or a fixed width:
#width = 650,
)
})
}
shinyApp(ui = ui, server = server)

I cannot get slider inputs to modify a map in shiny

I cannot get the map to react with the sliders. THe data was from https://www.kaggle.com/nasa/meteorite-landings/data#
when i move the sliders the map "refreshes" like it resets itself as if something were going to change but all of the data points show up on the graph. any help would be appreciated.
library(shiny)
library(dplyr)
library(leaflet)
library(ggplot2)
Meteor <- read.csv()
#to take all NA values out
ReMeteor <- na.omit(Meteor) #from now on using ReMeteor instead of Meteor
ui <- shinyUI(fluidPage(
titlePanel("Meteorite Landings"),
# Sidebar with a sliders and checkbox
sidebarLayout( position = "right",
sidebarPanel(
#1st slider year range
sliderInput("years","The year the meteorite fell, or the year it was found ",
min = min(ReMeteor$year),
max = max(ReMeteor$year),
step = 1,value = c(1399,2013),
animate = TRUE),
#2nd slider mass range
sliderInput("masss","The mass of the meteorite, in grams",
min = min(ReMeteor$mass),
max = max(ReMeteor$mass),
step = 100,value = c(.010,60000000),
animate = TRUE),
#checkbox
selectInput("fall",
"Was meteorite seen falling or found?",
choices = sort(unique(ReMeteor$fall))),
),
mainPanel( leafletOutput("my_leaf",height = 650, width = 605),textOutput("text1"),textOutput("text2")
))))
server <- shinyServer(function(input, output, session) {
#i think this block of four was letting it refresh, although no changes
filtered <- reactive({
ReMeteor[ReMeteor$year >= input$years[1] & ReMeteor$year <= input$years[2],]
ReMeteor[ReMeteor$mass >= input$masss[1] & ReMeteor$mass <= input$masss[2],]
})
#need last checkbox
# filter(ReMeteor >= input$year[1] &
# ReMeteor <= input$year[2]) %>%
# filter(ReMeteor >= input$mass[1] &
# ReMeteor <= input$mass[2])%>%
# filter(ReMeteor = sort(unique(ReMeteor$fall)))
# fitBounds()#here it is !!! https://rstudio.github.io/leaflet/shiny.html search : fitbounds --- this too https://rstudio.github.io/leaflet/markers.html
output$my_leaf <- renderLeaflet({
leaflet(data = filtered()) %>%
addMiniMap(zoomLevelOffset = -4) %>%
addProviderTiles("Esri.NatGeoWorldMap")
})
#fitBounds(ReMeteor, ReMeteor$reclong,ReMeteor$reclat,ReMeteor$reclong,ReMeteor$reclat)
observe({
# year_ <-input$year
# mass_ <-input$mass
# fall_ <-input$fall
#
leafletProxy("my_leaf", data = filtered()) %>%
clearShapes() %>%
clearMarkers() %>%
clearPopups() %>%
addMarkers(lat = ReMeteor$reclat,
lng = ReMeteor$reclong,
clusterOptions = markerClusterOptions(),
popup = as.character(ReMeteor$name,ReMeteor$recclass))
})
output$text1 <- renderText({
paste("You have chosen a range from the year", input$years[1], "to", input$years[2])
})
output$text2 <- renderText({
paste("You have chosen a range of mass from", input$masss[1], "to", input$masss[2], "grams")
})
})
shinyApp(ui, server)
The issue here is that although you correctly used the reactive value filtered() in your leafletProxy call, you use the non-reactive version of ReMeteor in your addMarkers call.
observe({
leafletProxy("my_leaf", data = filtered()) %>%
clearShapes() %>%
clearMarkers() %>%
clearPopups() %>%
addMarkers(lat = filtered()$reclat,
lng = filtered()$reclong,
clusterOptions = markerClusterOptions(),
popup = as.character(filtered()$name,filtered()$recclass))
})

Setting a "Reset Values" button on Shiny

I have put together a Shiny app that reactively creates lists while simultaneously removing those selections from the list you're selecting from. I'm trying to put together a feature where you click a reset button and it does the following:
1.) Deselects all input options
2.) Sets the Age Range to 18 - 104 (so it captures all values)
3.) Moves the other two sliders to zero
I'm trying to use the shinyjs::reset function, but it doesn't appear to be working. Take a look:
df <- read.csv('https://raw.githubusercontent.com/gooponyagrinch/sample_data/master/datasheet.csv')
library(shiny)
library(shinyWidgets)
library(shinyjs)
library(tidyverse)
library(DT)
ui <- fluidPage(
div(id = "myapp",
fluidRow(
column("",
width = 10, offset = 1,
tags$h3("Select Area"),
panel(
sliderInput("current", "Current Score",
min = 0, max = 100, value = 20),
sliderInput("projected", "Projected Score",
min = 0, max = 100, value = 20),
sliderInput("age", "Age",
min = 18, max = max(df$age), value = c(18,24)),
checkboxGroupInput("ethnicity",label = "Ethnicity",
choices = list("Caucasian"="Caucasian",
"African-American"="African-American",
"Hispanic"="Hispanic",
"Other"="Other")),
checkboxInput('previous', label = "Previous Sale"),
checkboxInput('warm', label = "Warm Lead"),
actionButton("button", "Add to List"),
actionButton("reset", "Reset form")),
textOutput("counter"),
tags$h2("Data to filter"),
DT::dataTableOutput("table"),
tags$h2("IDs added to list"),
DT::dataTableOutput("addedToList")
)
)
)
)
server <- function(input, output, session) {
filterData = reactiveVal(df %>% mutate(key = 1:nrow(df)))
addedToList = reactiveVal(data.frame())
filtered_df <- reactive({
res <- filterData() %>% filter(current_grade >= input$current)
res <- res %>% filter(projected_grade >= input$projected)
res <- res %>% filter(age >= input$age[1] & age <= input$age[2])
res <- res %>% filter(ethnicity %in% input$ethnicity | is.null(input$ethnicity))
if(input$previous == TRUE)
res <- res %>% filter(previous_sale == 1)
if(input$warm == TRUE)
res <- res %>% filter(warm_lead == 1)
res
})
output$counter <- renderText({
res <- filtered_df() %>% select(customer_id) %>% n_distinct()
res
})
output$table <- renderDataTable({
res <- filtered_df() %>% distinct(customer_id)
res
})
observeEvent(input$button, {
addedToList(rbind(addedToList(),
filterData() %>% filter(key %in% filtered_df()$key) %>%
select(customer_id) %>% distinct() ))
filterData(filterData() %>% filter(!key %in% filtered_df()$key))
})
observeEvent(input$reset, {
shinyjs::reset("myapp")
})
output$addedToList <- renderDataTable({
addedToList()
})
}
shinyApp(ui,server)
Am I missing something?
All you need to do is ensure that your application is listening for a call to "ShinyJS" in your application. In the UI, add the useShinyJS() call!
ui <- fluidPage(
useShinyJS()
div(id = "myapp",
fluidRow(...)
)
I also should note this looks like a repeat of this question. 'Reset inputs' button in shiny app

Display multiple summary statistics depending on user selection

I'm creating a shiny app where a user can select a state parent_location and a county name from two drop downs. They can also select a variable of interest layer which will then produce a summary statistics table. I've got my code working up to this point.
What I need to do is select other similar counties (contained in the cluster column) and then display summary statistics for this county as well. I can't seem to figure out how to A) display multiple summary statistics tables and B) dynamically create a list of similar counties.
Code that works
library(shiny)
library(tidyverse)
library(lubridate)
eviction_county_2010 <- read.csv("./eviction_county_2010.csv")
ui <- fluidPage(
sliderInput(inputId = "year",
label = "Select a Year:",
min = 2010,
max = 2016,
value = 2010,
step = 1),
radioButtons(inputId = "layer",
label = "Select a Dataset to View:",
choices = c("Eviction Filing Rate"="eviction_filing_rate", "Percent Rent Burden"="rent_burden",
"Percent Renter Occupied"="pct_renter_occupied", "Poverty Rate"="poverty_rate")),
selectInput(inputId = "state",
label = "Select a State:",
eviction_county_2010$parent_location),
selectInput(inputId = "county",
label = "Select a County:",
choices = NULL),
mainPanel(
h2("Summary of the variable"),
verbatimTextOutput("sum")
)
)
server <- function(input, output, session) {
observe({
x <- filter(eviction_county_2010,parent_location == input$state) %>%
select(name)
updateSelectInput(session,"county","Select a County:",choices = unique(x))}
)
output$sum <- renderPrint({
ec <- eviction_county_2010 %>%
filter(parent_location == input$state) %>%
filter(name == input$county)
summary(ec[,input$layer])
})
}
# Run the application
shinyApp(ui = ui, server = server)
Code I've attempted for displaying for similar counties. It returns Error in .getReactiveEnvironment()$currentContext(): Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.) I'm not sure which part needs to be placed inside a reactive expression.
ui <- fluidPage(
sliderInput(inputId = "year",
label = "Select a Year:",
min = 2010,
max = 2016,
value = 2010,
step = 1),
radioButtons(inputId = "layer",
label = "Select a Dataset to View:",
choices = c("Eviction Filing Rate"="eviction_filing_rate", "Percent Rent Burden"="rent_burden",
"Percent Renter Occupied"="pct_renter_occupied", "Poverty Rate"="poverty_rate")),
selectInput(inputId = "state",
label = "Select a State:",
eviction_county_2010$parent_location),
selectInput(inputId = "county",
label = "Select a County:",
choices = NULL),
mainPanel(
h2("Summary of the variable"),
verbatimTextOutput("sum")
)
)
server <- function(input, output, session) {
ec <- eviction_county_2010 %>%
filter(parent_location == input$state) %>%
filter(name == input$county)
sel_clust <- unique(ec$cluster)
sim_cty <- eviction_county_2010[ sample(which(eviction_county_2010$cluster == sel_clust), 4),]
sim_cty <- unique(sim_cty$GEOID)
sim_cty <- append(sim_cty, unique(ec$GEOID))
observe({
x <- filter(eviction_county_2010,parent_location == input$state) %>%
select(name)
updateSelectInput(session,"county","Select a County:",choices = unique(x))}
)
output$sum <- renderPrint({
df1 <- eviction_county_2010 %>%
filter(GEOID == sim_cty[1])
df2 <- eviction_county_2010 %>%
filter(GEOID == sim_cty[2])
df3 <- eviction_county_2010 %>%
filter(GEOID == sim_cty[3])
df4 <- eviction_county_2010 %>%
filter(GEOID == sim_cty[4])
df5 <- eviction_county_2010 %>%
filter(GEOID == sim_cty[5])
summary(df1[,input$layer])
summary(df2[,input$layer])
summary(df3[,input$layer])
summary(df4[,input$layer])
summary(df5[,input$layer])
})
}
# Run the application
shinyApp(ui = ui, server = server)
Is this even possible? What am I doing wrong here?
Move this section:
ec <- eviction_county_2010 %>%
filter(parent_location == input$state) %>%
filter(name == input$county)
sel_clust <- unique(ec$cluster)
sim_cty <- eviction_county_2010[ sample(which(eviction_county_2010$cluster == sel_clust), 4),]
sim_cty <- unique(sim_cty$GEOID)
sim_cty <- append(sim_cty, unique(ec$GEOID))
To a reactive({}) statement. I think that's where your error is.
For example:
ec <- reactive({
eviction_county_2010 %>%
filter(parent_location == input$state) %>%
filter(name == input$county)
sel_clust <- unique(ec$cluster)
sim_cty <- eviction_county_2010[ sample(which(eviction_county_2010$cluster == sel_clust), 4),]
sim_cty <- unique(sim_cty$GEOID)
sim_cty <- append(sim_cty, unique(ec$GEOID))
})
Then later in your sever code use:
ec() %>%
...stuff...

ggvis plot disappears at random Shiny

I have a strange problem in Shiny. My shiny app has one ggvis plot with layer_points() and several options to manipulate the plot . When I run my app sometimes everything works good even if I change all options, but sometimes ( I suppose there is no specific rule) plot disappers. Plot comes back when I change one of options but it is not cool.
I study this issue but I do not really know whether it is a solution for my problem.
When the plot disappears my Shiny app looks like:
This my code:
ui.R
library(ggvis)
library(markdown)
library(shiny)
library(dplyr)
library(magrittr)
shinyUI(
fluidPage(
h3("Title"),
fluidRow(
column(3,
wellPanel(
radioButtons("radio",h5("Select"),choices=list("All values","Selected values"),
selected="All values"),
conditionalPanel(
condition = "input.radio != 'All values'",
checkboxGroupInput("checkGroup",label = "",
choices,
selected = c("AT1","AT2"))
),
hr(),
radioButtons("dataset", label = h5("Drilldown"),
choices = list("2 Level" = "df1", "3 Level" = "df2")
),
hr(),
h5("Choice"),
selectInput("xvar", h6(""),
axis_vars_x,
selected = "value"),
selectInput("yvar", h6(""),
axis_vars_y,
selected = "number2"),
hr(),
uiOutput("slider")
)
),
column(9,
ggvisOutput("plot")
)
)
)
)
server.R
library(shiny)
shinyServer(function(input, output,session) {
datasetInput <- reactive({
switch(input$dataset,
df2 = df2,
df1 = df1)
})
axis_vara_y <- reactive({
switch(input$yvar,
number = 2,
number2 = 3)
})
output$slider <- renderUI({
sliderInput("inslider",h5(""), min = round(min(datasetInput()[,axis_vara_y()]),0)-1,
max = round(max(datasetInput()[,axis_vara_y()]),0)+1,
value = c(round(min(datasetInput()[,axis_vara_y()]),0)-1,
round(max(datasetInput()[,axis_vara_y()]),0)+1),
step = 0.5)
})
data <- reactive({
filteredData <- datasetInput()
axisData <- axis_vara_y()
if(!is.null(input$inslider)){
if(input$radio == "All values"){
filteredData <- filteredData %>%
filter(filteredData[,axisData] >= input$inslider[1],
filteredData[,axisData] <= input$inslider[2])
}
else {
filteredData <- filteredData %>%
filter(value %in% input$checkGroup,
filteredData[,axisData] >= input$inslider[1],
filteredData[,axisData] <= input$inslider[2])
}
}
return(filteredData)
})
data_point <- reactive({
data() %>%
mutate(id = row_number())
})
xvar <- reactive(as.symbol(input$xvar))
yvar <- reactive(as.symbol(input$yvar))
dotpoint_vis <- reactive({
xvar_name <- names(axis_vars_x)[axis_vars_x == input$xvar]
yvar_name <- names(axis_vars_y)[axis_vars_y == input$yvar]
data_point_detail <- data_point()
plot <- data_point_detail %>%
ggvis(x = xvar(),y = yvar()) %>%
layer_points(size := 120,fill = ~value) %>%
add_axis("x", title = xvar_name) %>%
add_axis("y", title = yvar_name) %>%
set_options(width = 750, height = 500, renderer = "canvas")
})
dotpoint_vis %>% bind_shiny("plot")
})
global.R
choices <- list("Value1" = "AT1", "Value2" = "AT2",
"Value3" = "AT3", "Value4" = "AT4",
"Value5" = "AT5", "Value6" = "RT1",
"Value7" = "AT6", "Value8" = "AT7",
"Value9" = "AT8", "Value10" = "AT9",
"Value11" = "AT10", "Value12" = "RT2")
levele <- c("AT1","AT2","AT3","AT4","AT5","RT1","AT6","AT7","AT8","AT9","AT10","RT2")
df1 <- data.frame(value = levele,number = seq(2,46,4), number2 = seq(2,24,2),order = 1:12)
df2 <- data.frame(value = levele,number = rep(4:15), number2 = rep(4:9,each = 2),order = 1:12)
df1$value <- factor(df1$value, levels = levele)
df2$value <- factor(df2$value, levels = levele)
axis_vars_y <- c("number","number2")
axis_vars_x <- c("value", "order","number","number2")
update
I also do not know what happened with animation in ggvis.
The problem was difficult to reproduce at first, but I found I can reproduce it by clicking back and forth between All Values and Selected Values. The graph disappears or reappears after some number of switches between the two radio buttons, but it varies seemingly randomly -- sometimes it takes 4 clicks to make the graph disappear or reappear and other times it takes 2 clicks or some other number of clicks.
There must be a bug in bind_shiny() or ggvisOutput(), because the following changes do create a graphic that does not seem to disappear:
In ui.R, make this change:
# ggvisOutput("plot")
plotOutput('plot')
In server.R, make this change:
plot(data_point_detail[ , c(input$xvar, input$yvar)], xlab=xvar_name, ylab=yvar_name)
# plot <- data_point_detail %>%
# ggvis(x = xvar(),y = yvar()) %>%
# layer_points(size := 120,fill = ~value) %>%
# add_axis("x", title = xvar_name) %>%
# add_axis("y", title = yvar_name) %>%
# set_options(width = 750, height = 500, renderer = "canvas")
# plot
and
output$plot <- renderPlot(dotpoint_vis())
# dotpoint_vis %>% bind_shiny("plot")

Resources