【发布时间】:2019-07-19 16:31:57
【问题描述】:
具体来说,我希望将闪亮的输入值输入到 Rhandsontable 上的下拉菜单中。通常,除了让用户编辑 rhandsontable 之外,我经常希望使用闪亮的输入来填写表格中的单元格和列。
这是一个突出我意图的小示例应用程序:
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 获取输入。
【问题讨论】:
标签: r shiny rhandsontable