Created
August 25, 2014 18:32
-
-
Save corynissen/4fb922fd991df3d0219d to your computer and use it in GitHub Desktop.
ggvis shiny issue
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(ggvis) | |
shinyServer(function(input, output, session) { | |
df <- mtcars | |
plot_data <- reactive({ | |
df$x <- df[,input$x_var] | |
# do some dynamic change of the data... | |
df <- df[-c(1:runif(1, 1, 10)),] | |
df$id <- 1:nrow(df) | |
df | |
}) | |
selected_plot_data <- reactive({ | |
df <- plot_data() | |
df$selected <- lb$selected() | |
df | |
}) | |
lb <- linked_brush(keys = plot_data()$id, "red") | |
plot_data %>% | |
ggvis(~x, ~mpg) %>% | |
layer_points(fill := lb$fill, fill.brush := "red") %>% | |
lb$input() %>% | |
set_options(width=800) %>% | |
bind_shiny('gg', 'gg_ui') | |
output$table <- renderDataTable({ | |
df <- selected_plot_data() | |
if(any(df$selected)){df <- subset(df, selected)} | |
df | |
}, options=list(bPaginate=FALSE)) | |
}) |
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(ggvis) | |
shinyUI(pageWithSidebar( | |
headerPanel('mtcars'), | |
sidebarPanel( | |
tags$head( | |
tags$style(type="text/css", "label.radio { display: inline-block; }", ".radio input[type=\"radio\"] { float: none; }"), | |
tags$style(type="text/css", "select { max-width: 200px; }"), | |
tags$style(type="text/css", "textarea { max-width: 185px; }"), | |
tags$style(type="text/css", ".jslider { max-width: 200px; }"), | |
tags$style(type='text/css', ".well { max-width: 250px; }"), | |
tags$style(type='text/css', ".span4 { max-width: 250px; }") | |
), | |
selectInput(inputId = "x_var", | |
label = "Select X Variable to Display", | |
choices = c("drat", | |
"wt", | |
"hp"), | |
selected = "wt") | |
), | |
mainPanel( | |
uiOutput('gg_ui'), | |
ggvisOutput('gg'), | |
dataTableOutput("table") | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment