when running a shiny app can one use rvest (or something similar) on the app itself? i am looking to use it to track user activity of a d3js during the run and update another part of the app (ie reactive)--
You received this message because you are subscribed to the Google Groups "shinyapps.io Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shinyapps-users/edef4f9c-2e7f-46bd-a0af-7c881503c9da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
i know how to import data, but i need to capture it in this case from d3. as for this example of filtering the datatable through selection in the d3 tree.
#global.r
library(shiny)
library(ggplot2)
library(shinyAce)
library(dplyr)
#From ggtree https://github.com/cpsievert/shiny_apps/tree/master/ggtree
# recursive approach! http://stackoverflow.com/questions/12818864/how-to-write-to-json-with-children-from-r
makeList <- function(x) {
idx <- is.na(x[,2])
if (ncol(x) > 2 && sum(idx) != nrow(x)){
listSplit <- split(x[-1], x[1], drop=T)
lapply(names(listSplit), function(y){list(name = y, children = makeList(listSplit[[y]]))})
} else {
nms <- x[,1]
lapply(seq_along(nms), function(y){list(name = nms[y], value = x[,"value"][y])})
}
}
# thanks Jeroen http://stackoverflow.com/questions/19734412/flatten-nested-list-into-1-deep-list
renquote <- function(l) if (is.list(l)) lapply(l, renquote) else enquote(l)
df2tree <- function(m) {
list(name = "ggplot", children = makeList(m))
}
m=mtcars%>%select(cyl,vs,am,gear,carb,mpg)%>%mutate(mpg=as.character(mpg))%>%rename(value=mpg)
#server.r
shinyServer(function(input, output, session) {
output$d3 <- reactive({
return(list(root = df2tree(m), layout = input$d3layout))
})
output$table <- renderDataTable(
m
)
})
#ui
shinyUI(fluidPage(
tags$head(
tags$script(type="text/javascript", src = "d3.v3.js"),
tags$script(type="text/javascript", src ="d3.tip.js"),
tags$script(type="text/javascript", src ="ggtree.js"),
tags$link(rel = 'stylesheet', type = 'text/css', href = 'ggtree.css')
),
fluidRow(
column(width = 6,
selectInput("d3layout", "Choose a layout:",
choices = c("Radial" = "radial",
"Collapsed" = "collapse",
"Cartesian" = "cartesian"),selected = "collapse"),
HTML("<div id=\"d3\" class=\"d3plot\"><svg /></div>")
),
column(width = 6,dataTableOutput('table'))
)
))