繁体   English   中英

在 R Shiny 中制作排行榜

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM