[英]Making a Leaderboard in R Shiny
I am attempting to make a leaderboard in R Shiny for my school where users could submit their name, teacher's name, and their score in textInputs by clicking an actionButton.我正在尝试为我的学校在 R Shiny 中制作排行榜,用户可以通过单击操作按钮在 textInputs 中提交他们的姓名、教师姓名和分数。 I am having trouble with the following:我遇到以下问题:
a) Making the textInputs submit on the push of the actionButton (I know I should use the isolate function, but have no idea where/when/how) a) 使 textInputs 在 actionButton 的推送上提交(我知道我应该使用隔离 function,但不知道在哪里/何时/如何)
b) Storing the info the user inputs with the data frame so that when the app opens on a second device it still shows the info the first person uses b) 将用户输入的信息与数据框一起存储,这样当应用在第二台设备上打开时,它仍会显示第一个人使用的信息
My code is below:我的代码如下:
### 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)
Figured it out.弄清楚了。 The best solution was to read in the df as a csv every time I open the app and then write the info back to a csv every time a score is added to the scoreboard.最好的解决方案是每次打开应用程序时将 df 作为 csv 读取,然后每次将分数添加到记分牌时将信息写回 csv。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.