Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript R:改变;高度“;gvisTimeline中矩形的属性_Javascript_R_D3.js_Svg_Shiny - Fatal编程技术网

Javascript R:改变;高度“;gvisTimeline中矩形的属性

Javascript R:改变;高度“;gvisTimeline中矩形的属性,javascript,r,d3.js,svg,shiny,Javascript,R,D3.js,Svg,Shiny,我在R闪亮的应用程序中使用gvisTimeline-应用程序: library(shiny) library(googleVis) ui <-fluidRow( tags$head( tags$script(src="https://d3js.org/d3.v3.min.js", {{ suppressDependencies("d3") }}) ), htmlOutput("timeline") ) server <- function(input, o

我在R
闪亮的应用程序中使用
gvisTimeline
-应用程序:

library(shiny)
library(googleVis)

ui <-fluidRow(
  tags$head(
    tags$script(src="https://d3js.org/d3.v3.min.js", {{ suppressDependencies("d3") }})
  ),
  htmlOutput("timeline")
  )

server <- function(input, output) {

dat <- data.frame(Term=c("1","2","3"),
                  President=c("Whashington", "Adams", "Jefferson"),
                  start=as.Date(x=c("1789-03-29", "1797-02-03", "1801-02-03")),
                  end=as.Date(x=c("1797-02-03", "1801-02-03", "1809-02-03")))

output$timeline <-renderGvis({
                    gvisTimeline(data=dat[,-1], rowlabel="President",
                    start="start", end="end")
          })
    }

shinyApp(ui, server)

如何将此代码集成到Shining应用程序中,以便从一开始就获得所需高度和y坐标的矩形?谢谢你的帮助

这里的问题是,页面加载几毫秒后,时间线就从Google服务器传输过来了。您需要在传输发生后执行JavaScript代码,即页面初始化后50或500毫秒。下面的代码将每50毫秒执行一次,这很有效,但还远远不够完美

  • 在UI中,您需要一个虚拟输出“uiOutput(“timelineAdjustment”)”:

  • 在服务器中,您需要按如下方式定义它:

    autoInvalidate50msec <- reactiveTimer(50, session)
    output$timelineAdjustment <- renderUI({
       autoInvalidate50msec()
       HTML("<script type='text/javascript'>d3.select('#timeline svg:nth-child(1) g:nth-child(5) rect:nth-child(2)').attr('height', 42).attr('y', 40);</script>")
    })
    
    自动失效50毫秒
    
    uiOutput("timelineAdjustment")
    
    autoInvalidate50msec <- reactiveTimer(50, session)
    output$timelineAdjustment <- renderUI({
       autoInvalidate50msec()
       HTML("<script type='text/javascript'>d3.select('#timeline svg:nth-child(1) g:nth-child(5) rect:nth-child(2)').attr('height', 42).attr('y', 40);</script>")
    })
    
    output$timelineAdjustment <- renderUI({
        HTML("<script type='text/javascript'>setTimeout(function() { d3.select('#timeline svg:nth-child(1) g:nth-child(5) rect:nth-child(11)').attr('height', 41).attr('y', 41); },1000);</script>")
    })