向Rhandsontable添加闪亮的输入和电抗

时间:2019-02-26 07:23:04

标签: r shiny rhandsontable

具体地说,我希望将闪亮的输入值输入Rhandsontable的下拉菜单中。通常,除了让用户编辑Rhansontable之外,我经常想使用闪亮的输入来填充表格中的单元格和列。

这是一个小示例应用程序,突出了我的意图:

library(rhandsontable)
library(shiny)

non_reactive_choices <- c('choice1', 'choice2', 'choice3', 'choice4', 'choice5', 'choice6', 'choice7', 'choice8')

DF <- data.frame(col_1 = 'original value',
             col_2 = 'original value',
             col_3 = 'original value',
             col_4 = 'original value')

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput('c1', label='first choice', choices = non_reactive_choices, selected = 'choice1'), 
      selectInput('c2', label='second choice', choices = non_reactive_choices, selected = 'choice2'), 
      selectInput('c3', label='third choice', choices = non_reactive_choices, selected = 'choice1'), 
      selectInput('c4', label='fourth choice', choices = non_reactive_choices, selected = 'choice2') 
    ),
    mainPanel(
      HTML('<br>'),
      HTML('<h3> The first table has pulldown of non-reactive values: it works</h3>'),
      rHandsontableOutput('hotable1'),
      HTML('<h3> The second tables pulldowns point to reactive values: it doesnt work</h3>'),
      rHandsontableOutput('hotable2'))
  )
)

server <- function(input, output, session) {

output$hotable1 <- renderRHandsontable({
rhandsontable(DF, width = 600, height = 200) %>%
  hot_col(col = 'col_1', type = "dropdown", source = non_reactive_choices) %>%
  hot_col(col = 'col_2', type = "dropdown", source = non_reactive_choices) %>%
  hot_col(col = 'col_3', type = "dropdown", source = non_reactive_choices) %>%
  hot_col(col = 'col_4', type = "dropdown", source = non_reactive_choices) 
})

  #here I combine the inputs and use them as the only choices for my dataframe dropdown columns

combined_inputs <- reactive({ 
   c(input$c1, input$c2, input$c3, input$c4)
    })


output$hotable2 <- renderRHandsontable({

    rhandsontable(DF, width = 600, height = 200) %>%
      hot_col(col = 'col_2', type = "dropdown", source = combined_inputs() ) %>%
      hot_col(col = 'col_3', type = "dropdown", source = combined_inputs() ) %>%
      hot_col(col = 'col_4', type = "dropdown", source = combined_inputs() ) 
  })

  }

shinyApp(ui, server)

我正在使用闪亮的运行时在Rmarkdown中编写实验程序-通常SOP包括制作96孔托盘用于生物化学实验。我需要根据他们的输入(他们正在使用什么样品,他们有多少样品,他们想要什么化验,等等)建立一个供用户使用的96孔托盘,然后允许他们将值记录到表格中。这不仅可以帮助用户设置实验,还可以向用户报告结果。

总的来说,我想将用户输入/响应值放入rhandsontable中,而不仅仅是从rhandsontable中获取输入。

1 个答案:

答案 0 :(得分:1)

为解决类似的问题以动态使用输入值,我使rhandsontable的反应性是对输入值使用了watchEvent触发器。