我搜索了一下,似乎google Motionchart的API不允许自定义工具提示等等。但我认为有一种方法可以使用getstate()来检索表中的信息,然后使用所选项来创建我无法直接在工具提示中执行的交互式按钮。
getstate的文档位于:https://google-developers.appspot.com/chart/interactive/docs/gallery/motionchart#getstate
我查看了googleVis软件包的文档,但没有信息。所以我的问题是有一种方法可以在R?中使用这个getdata功能。
提前致谢。
这将是代码的结构:
library(shiny)
library(DT)
library(googleVis)
library(RJSONIO)
shinyApp(
ui = fluidPage(
column(width=7,
htmlOutput("Plot_Fruits"),
actionButton("Current", label = "Get current fruits")),
column(width=5, dataTableOutput('Current_Fruits')
)),
server = function(input, output) {
output$Plot_Fruits <- renderGvis({
FinalPlot <- gvisMotionChart(Fruits, "Fruit", "Year")
FinalPlot
})
observe(input$Current,{}
#Here use the getState() as it is explained at:
#https://google-developers.appspot.com/chart/interactive/docs/gallery/motionchart#getstate
#To update myState dynamically and render the table appropiately
)
output$Current_Fruits <- renderDataTable({
#myState should be updated dynamically when the button is pressed.
myState <- '
{"uniColorForNonSelected":false,"yLambda":1,
"xZoomedDataMin":71,"nonSelectedAlpha":0,
"dimensions":{"iconDimensions":["dim0"]},"xZoomedDataMax":91,
"iconType":"BUBBLE","duration":{"timeUnit":"Y","multiplier":1},
"playDuration":15000,"sizeOption":"_UNISIZE","xLambda":1,
"yZoomedDataMax":91,"yAxisOption":"4","xZoomedIn":false,
"xAxisOption":"4","iconKeySettings":[{"trailStart":"2010",
"key":{"dim0":"Apples"}},{"trailStart":"2010",
"key":{"dim0":"Oranges"}}],
"yZoomedDataMin":71,"time":"2010","yZoomedIn":false,
"orderedByY":false,"colorOption":"2","showTrails":true,"orderedByX":false}
'
json_file <- fromJSON(myState)
json_file <- lapply(json_file, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
Current_F <- as.data.frame(do.call("rbind", json_file),stringsAsFactors = FALSE)
datatable(Current_F,escape = FALSE, rownames = TRUE,
selection = 'single')
})
}
)