How to load objects in the UI in Shiny

Asked

Viewed 42 times

1

Hello, good morning, good morning! I have no knowledge of the shiny, and I’m having trouble executing some actions.

I’d like him to execute one reactive by means of the selectInput, radioButtons, textInput (I don’t know if it would be textInput or numericInput).

The selectInput, select a culture, which server, would locate a value in a data.frame.

I tried to load a date. CULT_F in ui but the same when I was running the API was loaded its first line.

Why you want to carry an object (data.frame) in ui and that I found that there is a way to add values to a data.frame running the API, in which case I could register some culture in the future, and the API would be updated, since I would be loading the edited object every time I run.

another lack of knowledge of mine, is how to make in the case of lists, or fill boxes appear in front of the label, and not down.

Because I do not know I am not able to perform these actions, I would like if possible a help with practical answers, nothing to just cite the error you are giving by the program, without showing didactically how to solve it,

from now on I thank the good will of those who can help me!!!

follows the code, in the example are the data.frames used, but in the code of the ui I would use read.table().

shinyApp(

  ui = fluidPage(

    sidebarLayout(
      selectInput("CULT",label="Cultura",list("Abacaxi", "Açafrão", "Alfafa", "Algodão", "Amendoim",
                                           "Azeitona", "Banana", "Batata", "Beterraba", "Café",
                                           "Cana-de-açúcar", "Cebola", "Cítricas", "Ervilha", "Feijão", 
                                           "Fumo", "Girassol", "Melância", "Milho", "Pimenta", "Repolho", 
                                           "Soja", "Sorgo", "Tomate", "Trigo", "Uva")),
#selectInput("CULT","Cultura:",c(paste(CULT_F$CULTURA,sep="")))
      radioButtons("TEXTUR", label = "Textura:", choices = list("Arenosa" = 1, "Média" = 2, "Argilosa" = 3),selected = 1),
      textInput("ETc",  "ETc (mm):" , value = "ENTER")), 
    mainPanel(dataTableOutput("Dados_Solos"))),

server = function(input, output) {

  CULT_F<-structure(list(
    GRUPO = c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 
              3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 
              4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L), 
    CULTURA = structure(c(12L, 20L, 8L, 7L, 21L, 26L, 14L, 24L, 
                          3L, 15L, 13L, 5L, 1L, 17L, 18L, 25L, 
                          4L, 19L, 6L, 2L, 23L, 22L,  9L, 11L, 16L, 10L),
                        .Label = c("Abacaxi", "Açafrão", "Alfafa", "Algodão", "Amendoim",
                                   "Azeitona", "Banana", "Batata", "Beterraba", "Café",
                                   "Cana-de-açúcar", "Cebola", "Cítricas", "Ervilha", "Feijão", 
                                   "Fumo", "Girassol", "Melância", "Milho", "Pimenta", "Repolho", 
                                   "Soja", "Sorgo", "Tomate", "Trigo", "Uva"), class = "factor")), 
    class = "data.frame", row.names = c(NA, -26L))

GRUP_F<-structure(list(GRUPO = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
                                 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), ETC = c(2L, 3L, 
                                                                                      4L, 5L, 6L, 7L, 8L, 9L, 10L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
                                                                                      10L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 2L, 3L, 4L, 5L, 6L, 
                                                                                      7L, 8L, 9L, 10L), FATORF = c(0.5, 0.425, 0.35, 0.3, 0.25, 0.225, 
                                                                                                                   0.2, 0.2, 0.175, 0.675, 0.575, 0.475, 0.4, 0.35, 0.325, 0.275, 
                                                                                                                   0.25, 0.225, 0.8, 0.7, 0.6, 0.5, 0.45, 0.425, 0.375, 0.35, 0.3, 
                                                                                                                   0.875, 0.8, 0.7, 0.6, 0.55, 0.5, 0.45, 0.425, 0.4)), class = "data.frame", row.names = c(NA, 
                                                                                                                                                                                                            -36L))  
TEXTURA<-structure(list(TEXTU = structure(c(1L, 3L, 2L), .Label = c("Arenosa", 
                                                                    "Argilosa", "Média"), class = "factor"), COD = 1:3, VIB = c(26L, 
                                                                                                                                18L, 12L), CC = c(16L, 18L, 24L), PMP = c(7L, 9L, 12L), ZE = c(20L, 
                                                                                                                                                                                             30L, 40L), DA = c(1, 1.3, 1.5)), class = "data.frame", row.names = c(NA, 
                                                                                                                                                                                                                                                          -3L))


  SOLinput<-reactive({
   ETC<-ifelse(input$ETc<=2,2,
             ifelse(input$ETc>2 & input$ETc<=3,3,
                   ifelse(input$ETc>3 & input$ETc<=4,4,
                             ifelse(input$ETc>4 & input$ETc<=5,5,
                                   ifelse(input$ETc>5 & input$ETc<=6,6,
                                            ifelse(input$ETc>6 & input$ETc<=7,7,
                                                   ifelse(input$ETc>7 & input$ETc<=8,8,
                                                         ifelse(input$ETc>8 & input$ETc<=9,9,
                                                                ifelse(input$ETc>9,10,"ERRO_ETC")))))))))


        CULT<-CULT_F[CULT_F$CULTURA==input$CULT,]$GRUPO
        FF<-GRUP_F[GRUP_F$GRUPO==CULT & GRUP_F$ETC==ETC,]$FATORF
        DSOL<-TEXTURA[TEXTURA$COD==input$TEXTUR,]

        DTA<-((DSOL$CC-DSOL$PMP)/10)*DSOL$DA                                           # Disponibilidade Total de água: DTA (mm cm^-1)
        CTA<-DTA*DSOL$ZE                                                               # Capaciadade Total de Água: CTA, (mm cm^-1) 
        CRA<-ifelse(CTA*FF>0,ifelse(CTA*FF<1,1,CTA*FF))     # Conteúdo real de água: CRA, (mm)
        IRN<-CRA 
       cbind(data.frame(Cultura=input$CULT,FatorF=FF),DSOL,data.frame(DTA=DTA,CTA=CTA,CRA=CRA,IRN=IRN))
       })

  output$Dados_Solos<-renderTable({SOLinput()})
  })
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.