【发布时间】:2020-07-15 18:56:51
【问题描述】:
我正在尝试在 R Shiny 中为我的学校制作一个排行榜,用户可以通过单击操作按钮在 textInputs 中提交他们的姓名、教师姓名和分数。我遇到以下问题:
a) 使 textInputs 在 actionButton 的推送上提交(我知道我应该使用隔离功能,但不知道在哪里/何时/如何)
b) 将用户输入的信息与数据框一起存储,这样当应用在第二台设备上打开时,它仍会显示第一个人使用的信息
我的代码如下:
### Libraries
library('tidyverse')
library('readxl')
library('shiny')
library('DT')
# Define UI
ui <- fluidPage(
# Application title
titlePanel("Scoreboard"),
# Sidebar
sidebarLayout(
sidebarPanel(
h5("Sidebar Text"),
),
# Main Panel
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Add Score",
textInput("name_input", "Insert Your Name Below"), textInput("teacher_input", "Insert Your Teacher's Last Name Below"),
textInput("score_input", "Insert Your Score Below"),
actionButton("sumbit_button", "Click Button to Submit!")
),
tabPanel("ScoreBoard", dataTableOutput("score_table"))
)
)
)
)
# Define server logic
server <- function(input, output) {
# Read In Sample Scores as a base dataframe to add user inputs to.
scores <- read_excel("Sample_Scores.xlsx")
scores <- scores[order(scores$Scores, decreasing = FALSE),]
names(scores) <- c("Score", "Name", "Teacher")
output$score_table <- renderDataTable({
new_score <- input$score_input
new_name <- input$name_input
new_teacher <- input$teacher_input
new_student <- c(new_score, new_name, new_teacher)
scores <- rbind(scores, new_student)
})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】: