Created
March 31, 2017 18:58
-
-
Save McClellandLegge/143011ce40e4982164156165710693c2 to your computer and use it in GitHub Desktop.
Null Plotly Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("shiny") | |
library("plotly") | |
set.seed(100) | |
d <- diamonds[sample(nrow(diamonds), 1000), ] | |
ui <- fluidPage( | |
titlePanel("Null Plotly Object"), | |
sidebarLayout( | |
sidebarPanel( | |
checkboxGroupInput("cuts", "Cut", choices = sort(unique(d$cut))) | |
), | |
mainPanel( | |
plotlyOutput("distPlot") | |
) | |
) | |
) | |
server <- function(input, output) { | |
plot_dat <- reactive({ | |
shiny::validate( | |
need(input$cuts, "Select a cut") | |
) | |
d[d$cut %in% input$cuts, ] | |
}) | |
output$distPlot <- renderPlotly({ | |
plot_ly(plot_dat(), x = ~carat, y = ~price, color = ~carat, type = "scatter", | |
mode = "markers", size = ~carat, text = ~paste("Clarity: ", clarity)) | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment