[英]Making a Leaderboard in R Shiny
我正在嘗試為我的學校在 R Shiny 中制作排行榜,用戶可以通過單擊操作按鈕在 textInputs 中提交他們的姓名、教師姓名和分數。 我遇到以下問題:
a) 使 textInputs 在 actionButton 的推送上提交(我知道我應該使用隔離 function,但不知道在哪里/何時/如何)
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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.