When using the code:
library(shiny)
library(ggvis)
library(ggplot2)
ui <- fluidPage(
uiOutput("ggvis_ui"),
ggvisOutput("ggvis"),
tags$em("Data taken from the Housing Sales in Texas data set in ggplot2 ",
tags$a(href = "https://ggplot2.tidyverse.org/reference/txhousing.html", target = "_blank", "found here")),
hr(),
fluidRow(column(3,
sliderInput(inputId = "alpha",
label = "Choose an alpha (lower = more transparent)",
value = 0.5, min = 0, max = 1),
radioButtons(inputId = "color",
label = "Choose a color",
choices = list("teal" = "turquoise", "blue" = "royalblue", "navy" = "navy", "green" = "green"))),
column(3,
selectInput("y_var", label = "select y variable",
choices = list("sales" = "sales", "volume" = "volume", "listings" = "listings", "median" = "median"),
selected = "sales"))
)
)
server <- function(input, output) {
input_alpha <- reactive(input$alpha)
input_color <- reactive(input$color)
plot_data <- reactive({
df <- txhousing[,c("month", input$y_var)]
names(df) <- c("month", "y")
df})
plot_data %>% ggvis(x = ~month, y = ~y) %>%
layer_histograms(fill := input_color, fillOpacity := input_alpha) %>%
bind_shiny("ggvis", "ggvis_ui")
}
shinyApp(ui = ui, server = server)
My shiny will not load and gives me the error that input_color is not found.
When I run the code with quotations (as follows), it works but none of my commands are making a difference on my app:
library(shiny)
library(ggvis)
library(ggplot2)
ui <- fluidPage(
uiOutput("ggvis_ui"),
ggvisOutput("ggvis"),
tags$em("Data taken from the Housing Sales in Texas data set in ggplot2 ",
tags$a(href = "https://ggplot2.tidyverse.org/reference/txhousing.html", target = "_blank", "found here")),
hr(),
fluidRow(column(3,
sliderInput(inputId = "alpha",
label = "Choose an alpha (lower = more transparent)",
value = 0.5, min = 0, max = 1),
radioButtons(inputId = "color",
label = "Choose a color",
choices = list("teal" = "turquoise", "blue" = "royalblue", "navy" = "navy", "green" = "green"))),
column(3,
selectInput("y_var", label = "select y variable",
choices = list("sales" = "sales", "volume" = "volume", "listings" = "listings", "median" = "median"),
selected = "sales"))
)
)
server <- function(input, output) {
"input_alpha" <- reactive(input$alpha)
"input_color" <- reactive(input$color)
"plot_data" <- reactive({
df <- txhousing[,c("month", input$y_var)]
names(df) <- c("month", "y")
df})
plot_data %>% ggvis(x = ~month, y = ~y) %>%
layer_histograms(fill := "input_color", fillOpacity := "input_alpha") %>%
bind_shiny("ggvis", "ggvis_ui")
}
shinyApp(ui = ui, server = server)
I am not sure where I am going wrong. I want it to load, as it does in the second code, then have my commands make an actual change. Thanks in advance for the help.