2014-09-10 63 views
0

我试图用[R闪亮用下面的代码:Highcharts stickyTracking

server.R

require(rCharts) 
shinyServer(function(input, output) { 
    output$myChart <- renderChart({ 
    names(iris) = gsub("\\.", "", names(iris)) 
    p1 <- hPlot(input$x, input$y, data = iris, type = c("scatter")) 
    p1$plotOptions(series = list(stickyTracking = FALSE)) 
    p1$addParams(dom = 'myChart') 
    return(p1) 
    }) 
}) 

ui.R

require(rCharts) 
shinyUI(pageWithSidebar(
    headerPanel("highcharts"), 

    sidebarPanel(
    selectInput(inputId = "x", 
    label = "Choose X", 
    choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'), 
    selected = "SepalLength"), 
    selectInput(inputId = "y", 
     label = "Choose Y", 
     choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'), 
     selected = "SepalWidth") 
), 
    mainPanel(
    showOutput("myChart", "highcharts") 
) 
)) 

应用程序是在线浏览:http://alligaator.at.mt.ut.ee:8100/users/metsalu/test2/。问题是,如果我将鼠标悬停在某些点上,然后走出阴谋,工具提示仍然显示。我预计stickyTracking = FALSE会关闭它。我错过了什么吗?

我也尝试使用tooltip的followPointer选项,但没有成功。

+0

由于旧版本的highCharts与jQuery发生冲突,此功能不正确。请参阅http://stackoverflow.com/questions/25513790/no-auto-resize-of-yaxis-of-highcharts-in-shiny/25516138#comment39842882_25516138。希望更新的JavaScript库将被添加到rCharts https://github.com/ramnathv/rCharts/issues/521。在此之前,您可以使用'options(rcharts.cdn = TRUE)'。 – jdharrison 2014-09-10 12:02:21

回答

0

这是由于highCharts JavaScript库的旧副本和较新的JQuery库之间的冲突造成的。一个临时解决方案是使用CDN而不是本地脚本:

library(rCharts) 
library(shiny) 
options(rcharts.cdn = TRUE) 

runApp(
    list(ui = pageWithSidebar(
    headerPanel("highcharts"), 

    sidebarPanel(
     selectInput(inputId = "x", 
        label = "Choose X", 
        choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'), 
        selected = "SepalLength"), 
     selectInput(inputId = "y", 
        label = "Choose Y", 
        choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'), 
        selected = "SepalWidth") 
    ), 
    mainPanel(
     showOutput("myChart", "highcharts") 
    ) 
) 
    , server = function(input, output) { 
    output$myChart <- renderChart({ 
     names(iris) = gsub("\\.", "", names(iris)) 
     p1 <- hPlot(input$x, input$y, data = iris, type = c("scatter")) 
     p1$plotOptions(series = list(stickyTracking = FALSE)) 
     p1$addParams(dom = 'myChart') 
     return(p1) 
    }) 
    }) 
) 
+0

谢谢你的解释,这工作! – 2014-09-11 07:44:43