Insert values in shiny app.

Hi community

Im have some questions about Shiny. Im need make an app for insert or in put values in different field.
Like zone, type, temperature, etc.

The idea is capture the data and have a final data frame.

But I dont know if is possible with shiny, because Im use this for makes presentation and dashboards.

The first step is in put the data and next make dashboard.

Tnks for the suggestions

Hi Hope it helps,
you can enter data and save it in a data frame. You have option to download the data frame as csv. **Please note, the first row will appear in the table , when you add the second, **

library(shiny)
library(shinydashboard)
library(dplyr)
library(DT)
library(shinyjs)

ui <- fluidPage(
  align='center',
  textAreaInput(inputId = 'mValueEntered',
                label = 'Enter values just with comma',
                value = "1,A,25,A1"),
  
  actionButton(inputId = 'mSaveBtn',label = 'Save'),
  DT::dataTableOutput(outputId = 'mShowTbl',width = '500px'),
  downloadButton("downloadCSVBtn", "Download Dataset CSV")
  
)


server <- function(input, output, session) {
  rv <- reactiveValues(df=NULL)
  
  df <- list()
  
  observeEvent(input$mSaveBtn,{
    if (is.data.frame(df)==FALSE){
      df <- data.frame(Zone=integer(),
                       type = character(),
                       Temperature= double(),
                       Cow = character())
    }
    
    cc<- as.list(scan(text = input$mValueEntered, what = "", sep = ","))
    cc<-data.frame(mData=unlist(cc))
    
    df<<- df %>% add_row(
      Zone=as.numeric(cc[1,1]),
      type = cc[2,1],
      Temperature= as.numeric(cc[3,1]),
      Cow = cc[4,1])
    
    
    rv$df <- df

  })
  
  
  
  output$mShowTbl <- DT::renderDataTable({
    DT::datatable(rv$df,
                  rownames = FALSE,
                  width = NULL,
                  height = NULL,
                  editable = TRUE,
                  selection = list(mode = "single", selected = c(1), target = 'row'),
                  options = list(
                    scrollY = '325px',
                    class="compact",
                    paging = FALSE,
                    searching = FALSE,
                    ordering = FALSE,
                    initComplete = JS(
                      "function(settings, json) {",
                      "$(this.api().table().header()).css({'background-color': 'steelblue', 'color': '#fff'});",   
                      "}")
                  )
    ) 
  })
  
  ##########################################################################
  # Code to download dataset as csv and rds
  ##########################################################################
  output$downloadCSVBtn<- downloadHandler(
    filename = function() {
      paste("mydata", Sys.Date(), ".csv", sep="")
    },
    content = function(file) {
      write.csv(data.frame(rv$df), file, row.names = FALSE)
    }
  )
  

}

shinyApp(ui, server)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.