在shiny app中访问React性输入和用户的文本输入,以便稍后保存到sql数据库

lqfhib0f  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(233)

我是一个新手,当谈到闪亮的应用程序。我花了两天的时间寻找解决我的难题的方法,但似乎什么都不管用。
这是我的问题。我闪亮的应用程序的一部分在ui上显示了一个pdf。最终用户将阅读该pdf并对其发表评论。最终用户可以在页面右侧添加任意多的评论(也可以删除评论)。
每个注解都在一个单独的textareainput上进行。每个textareainput都是通过单击actionbutton创建的。
因为每个textareainput都包含在一个React对象(我称之为commentarios)中,所以它们都有一个唯一的id。
我的问题是:我需要访问React对象“commentarios”中的每个textareainput id和comment文本,以便将其保存到sqlserver数据库。下面是代码的摘录。我真的很感激你能提供的任何帮助!

library(shiny)

ui <- fluidPage(
  sidebarPanel(
    fileInput(inputId = "file_input", h4("Worksheet (pdf only)"), accept = c(".pdf"))),
  mainPanel(
    tabPanel(title = ("WORKSHEET"),icon = icon("file-alt"),
             column(9,
                    br(),
                    uiOutput("pdfview")),
             column(3, 
                    br(),
                    div(style="display:inline-block;width:120px;text-align: left, padding: 30px; float:left;margin-left: 10px;",
                        actionBttn(
                          inputId = "new_com",
                          label = "New Comment", 
                          style = "gradient",
                          color = "success",
                          icon = icon("comment"),
                          size = "sm")),
                    div(style="display:inline-block;width:120px;text-align: left, padding: 30px; float: left;margin-left: 10px;",
                        actionBttn(inputId = "deleting_com", 
                                   label = "Remove Comment",
                                   style = "gradient",
                                   color = "primary",
                                   icon = icon("comment-slash"),
                                   size = "sm")),
                    uiOutput("comentarioz")))))

server <- function(input, output, session){
  #FUNCTION TO DISPLAY PDF in WORKSHEET
  observe({  
    if(is.null(input$file_input)){
      output$pdfview <- renderUI({
        tags$iframe(style="height:1200px; width:100%", src = "")})}
    else{
      file.copy(input$file_input$datapath,"www", overwrite = T)
      output$pdfview <- renderUI({
        tags$iframe(style="height:2000px; width:100%", src="0.pdf")
        })}})

  ########################################################################
  ### I suspect this is not very efficient code, but it does the deed
  clock <- reactiveValues(k = 0)
  previousclock <- reactiveValues(k = 0)

  observeEvent(input$new_com, 
               {clock$k <- clock$k + 1
               previousclock$k <- clock$k - 1})

  observeEvent(input$deleting_com, {
    if (clock$k > 0) {
      clock$k <- clock$k - 1
      previousclock$k <- clock$k + 1}})

    comentarios <- reactive({
      k <- clock$k    
      if(k > 0){
        if(previousclock$k > 0){
          valores = c()
          if(previousclock$k > k) {
            less <- k
            isInclud <- FALSE
            }else{
              less <- previousclock$k
              isInclud <- TRUE}

          for(i in 1:less){
            inputID = paste0("comentame",i)
            valores[i] = input[[inputID]]

          }

          if(isInclud){
            valores <- c(valores, "")
          }
          lapply(seq_len(k), function(i) {
            textAreaInput(inputId = paste0("comentame", i),
                          label = h5("COMMENT",i), value = valores[i],rows = 5, height = "70px",  resize = "vertical") %>% shiny::tagAppendAttributes(style = 'width: 100%;')
            })}

        else{
          lapply(seq_len(k), function(i){
            textAreaInput(inputId = paste0("commentame", i), label = h5("COMMENT",i) ,
                          value = "") %>% shiny::tagAppendAttributes(style = 'width: 100%;')
            })}
        }})

    output$comentarioz <- renderUI({comentarios()})

    }

shinyApp(ui = ui, server = server)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题