r - 在 R Shiny 中制作排行榜
问题描述
我正在尝试为我的学校在 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)
解决方案
弄清楚了。最好的解决方案是每次打开应用程序时将 df 作为 csv 读取,然后每次将分数添加到记分牌时将信息写回 csv。
推荐阅读
- android - 如何在回收器视图中为 RadioButton 添加动作事件?
- css - 带CSS的标题和副标题的领导者
- php - 如何输入回显值完成查询?
- c - 你能以编程方式检测C中函数的字节大小吗
- hyperledger-fabric - 我们可以修改超级账本作曲家中的交易记录吗
- spring-boot - 使用 MINA 2 为 Spring 配置 Camel
- wordpress - 如何在联系表 7 中使文件上传为“必需”?
- javascript - 等于节点模块的未定义变量
- excel - VBA图表单元格区域中的空白值
- swift - 调用 setNeedsStatusBarAppearanceUpdate() 后,prefersStatusBarHidden 不更新