Problems in UI interaction with conditioning

Asked

Viewed 36 times

1

Hello, good morning!

I’m having trouble calculating soil variables. the code keeps saying: argument is of length zero. The control has to work as follows:

1 select the crop, in the tab "Culture" (tabName="CULT_DATA"), selectInput(inputId="CULT"...).

2 In the "Handling tab" (tabName="MANEG_DATA"), select the option radioButtons("TP_MANEJ",...).

3 In the "Weather tab" (tabName="WEATH_DATA"), fill in the values of "Etc" textInput("ETC",...), and "Pe" textInput("Pe",...).

4 In the "Soils tab" (tabName="SOIL_DATA"), if the option: "Automatic ground data" is selected input$AUTO_SOL==T, he should check in input$TP_MANEJ the option selected.

To input$TP_MANEJ==1, carry out the calculations with the values of: CC, PMP, Da and ZE, available in tables (CULT_F, GROUP_F, TEXTURE).

To input$TP_MANEJ==2, use the values in input$ETc, and input$Pe.

If the option input$AUTO_SOL==F, it must use the data of input$CC, input$PMP, input$Da, input$ZE, provided by the user.

follows below the code I’m trying to fix:

shinyApp(

  ui <- dashboardPage(

    dashboardHeader(),

    dashboardSidebar(

      sidebarMenu(
        menuItem("Cultura",      tabName = "CULT_DATA"),
        menuItem("Clima",        tabName = "WEATH_DATA"),
        menuItem("Solo",         tabName = "SOIL_DATA"),
        menuItem("Manejo",       tabName = "MANEG_DATA")
      )),

    dashboardBody(

    tabItems(

tabItem(tabName="CULT_DATA",
        sidebarPanel(
          fluidRow(
            selectInput("CULT",label="Cultura",c(paste(CULT_F$CULTURA,sep=""))),
            column(6, textInput("ZE","Z (cm):",value=0)),
            column(6, textInput("FF","Fator f",value=0))))
),

tabItem(tabName="MANEG_DATA",
        sidebarPanel(
          radioButtons("TP_MANEJ",label="Manejo:",choices=list("Solo"=1,"Clima"=2)),
          fluidRow(
            column(5, textInput("Pi","Pi (dias):",value=0),
                   textInput("H","H(horas):",value=0),
                   textInput("Eapli","EA(%):",value=0))))
),

tabItem(tabName="WEATH_DATA",
        sidebarPanel(Title="Dados do Clima",
                     fluidRow(
                       column(8, textInput("ETc","ETc (mm):",value=0)),
                       column(8, textInput("Pe","Pe (mm):",value=0))))
),

tabItem(tabName="SOIL_DATA",
        sidebarPanel(
          fluidRow(
            column(6, textInput("CC","CC (%):",value=0),
                   textInput("Da","Da (g/cm3):",value=0)),
            column(6, textInput("PMP","PMP (%):",value=0),
                   textInput("VIB","VIB (mm/h):",value=0))),
          checkboxInput("AUTO_SOL",label="Dados do solo automático:",FALSE),
          radioButtons("TEXTUR",label="Textura:",choices=list("Arenosa"=1,"Média"=2,"Argilosa"=3))),
        mainPanel(tableOutput("Dados_solos"))
)))),

server <- function(input, output) {

# Tabelas!!! no caso eu estou carregando elas usando source("tabelas"), 
# que  carregam os comandos read.csv() de cada uma

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))


get.ETC<-function(X){ifelse(X<=2,2,
ifelse(X>2&X<=3,3,
ifelse(X>3&X<=4,4,
ifelse(X>4&X<=5,5,
ifelse(X>5&X<=6,6,
ifelse(X>6&X<=7,7,
ifelse(X>7&X<=8,8,
ifelse(X>8&X<=9,9,
ifelse(X>9,10,"ERRO_ETC")))))))))}


  observe({
    #source("IrIgA/TABELAS/TAB.R")
    #source("IrIgA/FUN/FUN.R")

    ETC<-get.ETC(input$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,]

  })


# Tentando fazer a reação com base nas condicionantes input$MANEJO, input$AUTO_SOL

    # saída deveria ser na forma de tabela com as respostas de IRN,DTA,CTA,CRA, 
# dentre outros. Mas meu interesse é usar esses objetos nos cálculos futuros.


  SOLOS<-reactive({


    if(input$TP_MANEJO==1)
      return({
        if(input$AUTO_SOL==TRUE)
          return({
            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})

        if(input$AUTO_SOL==FALSE)
          return({
            DTA<-((input$CC-input$PMP)/10)*input$Da                                                          # Disponibilidade Total de água: DTA (mm cm^-1)
            CTA<-input$DTA*input$ZE                                                                     # Capaciadade Total de Água: CTA, (mm cm^-1) 
            CRA<-ifelse(CTA*input$FF>0,ifelse(CTA*input$FF<1,1,CTA*input$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))
      })

    if(input$TP_MANEJ==2)
      return({IRN<-round(input$ETc+0.02,0)

      cbind(data.frame(Cultura=input$CULT,FatorF=input$FF,Z=input$ZE),data.frame(IRN=IRN))})

  })

  output$Dados_solos<-renderTable({SOLOS()})

})
  • have you managed to solve this problem? If yes put the answer here and accept the answer.

  • I will do this, but without time to organize the script, postponing that it was under "if" conditions, after double equality the value to be compared has to stay between single quotes input$TP_MANEJ=='2') .

No answers

Browser other questions tagged

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