用Shiny返回表中的当前位置

时间:2016-09-27 18:16:45

标签: r shiny

我正在为Shiny应用程序构建/添加内容,该应用程序主要用于查看单个样本的集合,以手动校正给定样本的单个参数。目前我使用滑块来翻阅图表,当前样本的单元格将显示在图表下方,供用户更正给定参数。

然而,这将要求用户将光标从滑块移动到单元格,然后再次返回滑块。为了简化我想到的过程,为什么不在用户按下向下键(向下移动一个单元格)时制作一个可以翻转图表的反应表。这将需要某种程度的测量表中的当前位置,其中用户是#34;站立"。所以我的问题是这是否可以在Shiny框架中完成?

这是我认为它可以发挥作用的图片。

Going one row down in the table should have a response to switch to the next plot.

由于

2 个答案:

答案 0 :(得分:0)

如果没有可重复的示例,我无法帮助您,但如果我理解您的问题,您只需要一种机制来在服务器中保持计数,这样您就可以知道用户所处的位置编号。这是一个简单的应用程序,可以按下上下按钮:

library(shiny)

# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
  # Sidebar with a slider input for number of bins
  sidebarLayout(sidebarPanel(
    actionButton("up","Increase value"),
    tags$br(),
    actionButton("down","Decrease value")
  ),

  # Show a plot of the generated distribution
  mainPanel(
    verbatimTextOutput("value")
  ))
))

# Define server logic required to draw a histogram
server <- shinyServer(function(input, output, session) {
 # initiate count at zero
  count <- reactiveValues(number=0)

  observeEvent(input$up,{
    count$number <- count$number + 1
  })

  observeEvent(input$down,{
    count$number <- count$number - 1
  })

  output$value <- renderPrint({
    count$number
  })

})

# Run the application
shinyApp(ui = ui, server = server)

答案 1 :(得分:0)

您可以使用DT在服务器端获取所选列。

为此,您只需将renderDataTable替换为DT::renderDataTable,将dataTableOutput替换为renderDataTableOutput.

library(DT)
library(shiny)

ui = fluidPage(
  verbatimTextOutput("text"),
  DT::dataTableOutput("mytable")
)

server = function(input, output, session){
  output$mytable = DT::renderDataTable({ mtcars })

  output$text = renderPrint({
    cat("selected rows:", input$mytable_rows_selected)
  })
}

shinyApp(ui,server)

将此与DT::selectColumnsthis technique相结合可以完成这项工作。