[英]Populate a dataframe with two actionButtons
I'm a bit stuck on this shiny problem.我有点卡在这个 shiny 问题上。 I have two actionButtons representing group membership (group 1 vs. group 2).
我有两个 actionButtons 代表组成员(第 1 组与第 2 组)。 I'd like if a user clicks one button to populate a two column data-frame with the group selected and the date/time it was submitted and for it to show on the page.
我想如果用户单击一个按钮来填充一个两列的数据框,其中包含所选的组和提交的日期/时间,并显示在页面上。 I can get the group + date/time to print to console on click but I could use some help getting to populate a table.
我可以让组 + 日期/时间在单击时打印到控制台,但我可以使用一些帮助来填充表格。
Here's what I've tried so far:到目前为止,这是我尝试过的:
library(shiny)
ui <- fluidPage(
titlePanel("Select your group"),
br(),
column(
6,
actionButton("group1", "Group 1", style = 'padding:4px; font-size:50px'),
),
column(
6,
actionButton("group2", "Group 2", style = 'padding:4px; font-size:50px'),
)
)
server <- function(input, output, session) {
click <- date()
observeEvent(input$group1, {print(paste0("Group1: ", click))})
observeEvent(input$group2,{print(paste0("Group2: ", click))})
}
shinyApp(ui, server)
Thanks for taking a look谢谢参观
Here is an idea.这是一个想法。 Everytime you click on a button the table gets a new row with information.
每次单击按钮时,表格都会获得一个包含信息的新行。 For a better impression the hole table is shown on the user interface.
为了获得更好的印象,孔表显示在用户界面上。
library(shiny)
ui <- fluidPage(
titlePanel("Select your group"),
br(),
column(
6,
actionButton("group1", "Group 1", style = 'padding:4px; font-size:50px'),
),
column(
6,
actionButton("group2", "Group 2", style = 'padding:4px; font-size:50px'),
),
br(),
tableOutput('table')
)
server <- function(input, output, session) {
values <- reactiveValues()
values$df <- data.frame(group = NA, time = NA)
observeEvent(input$group1, {
newLine <- c("group1", date())
isolate(values$df <- rbind(values$df, newLine))
})
observeEvent(input$group2, {
newLine <- c("group2", date())
isolate(values$df <- rbind(values$df, newLine))
})
output$table <- renderTable(values$df)
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.