2016-06-21 62 views
2

我正在编程一个更大的闪亮界面,ui.r mainPanel包含一个带有多个tabPanel的tabsetPanel,并且位于每种不同类型的表格和绘图输出中。除了需要滚动的页面倾向于在他们的滚动位置上跳转时,例如(重新)选择绘图输出,表格条目等,跳转有时看起来很棒。有时跳转到页面的开始处,有时跳到其他地方;它们都出现在Firefox和Chrome中。因此,有没有办法来防止或抑制这种跳跃?非常感谢您的帮助。滚动后闪亮的页面跳转

下面是一个小例子,其中用户界面跳转到页面顶部的选择表中的行页面的底部形成之后:

library(shiny) 
library(DT) 
data=data.frame(x=1:10,y=2:11) 

ui=shinyUI(
    fluidPage(
    plotOutput("plot1"), 
    plotOutput("plot2"), 
    DT::dataTableOutput("tt") 
) 
) 

server=shinyServer(function(input, output) { 
    dd=reactiveValues(d=data) 
    output$plot1 <- renderPlot({plot(0,1)}) 
    output$plot2 <- renderPlot({plot(0,1)}) 
    output$tt=DT::renderDataTable(
    datatable(
     dd$d,selection =c('single') 
    ) 
) 
    observeEvent(input$tt_rows_selected,{ 
    dd$d[input$tt_rows_selected,1]<-log(dd$d[input$tt_rows_selected,1]) 
    }) 
}) 

shinyApp(ui,server) 
+0

您能否包含一些示例代码?我不是很了解你的问题,并提供一个[可重现的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)将是非常有益的。 –

+1

当然,在上面补充说。 – martin

回答

0
library(shiny) 
library(DT) 
data=data.frame(x=1:10,y=2:11) 

ui=shinyUI(
    fluidPage(
    plotOutput("plot1"), 
    plotOutput("plot2"), 
    DT::dataTableOutput("tt") 
) 
) 

server=shinyServer(function(input, output) { 
    dd=reactiveValues(d=data) 
    output$plot1 <- renderPlot({plot(0,1)}) 
    output$plot2 <- renderPlot({plot(0,1)}) 
    output$tt=DT::renderDataTable(
    datatable(
     data,selection ='single' 
    ) 
) 
    observeEvent(input$tt_rows_selected,{ 
    dd$d[input$tt_rows_selected,1]<-log(dd$d[input$tt_rows_selected,1]) 
    }) 
}) 

shinyApp(ui,server) 

这适用于我。问题是selection = c('single')。它应该是selection = 'single'。在DT::datatable的文档中,您可以传递给selection的参数包含在c()中,仅用于指示所有选项。

+1

谢谢。但是没有 - 这不起作用;在你的例子中,你用数据替换了renderDataTable中的dd $ d。这使得_rows_selected的observeEvent已过时。没有响应行选择,没有跳跃 - 以任何方式“单一”可能被定义。也许你可以考虑从这篇文章中删除你的例子吗? – martin