pest | elegant PHP testing Framework with a focus on simplicity | REST library

 by   pestphp PHP Version: v2.1.0 License: MIT

kandi X-RAY | pest Summary

pest is a PHP library typically used in Web Services, REST, Framework applications. pest has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
We would like to extend our thanks to the following sponsors for funding Pest development. If you are interested in becoming a sponsor, please visit the Nuno Maduro's Sponsors page.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        pest has a medium active ecosystem.
                        summary
                        It has 6550 star(s) with 196 fork(s). There are 49 watchers for this library.
                        summary
                        There were 9 major release(s) in the last 6 months.
                        summary
                        There are 8 open issues and 351 have been closed. On average issues are closed in 8 days. There are 2 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of pest is v2.1.0
                        pest Support
                          Best in #REST
                            Average in #REST
                            pest Support
                              Best in #REST
                                Average in #REST

                                  kandi-Quality Quality

                                    summary
                                    pest has 0 bugs and 22 code smells.
                                    pest Quality
                                      Best in #REST
                                        Average in #REST
                                        pest Quality
                                          Best in #REST
                                            Average in #REST

                                              kandi-Security Security

                                                summary
                                                pest has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                pest code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 1 security hotspots that need review.
                                                pest Security
                                                  Best in #REST
                                                    Average in #REST
                                                    pest Security
                                                      Best in #REST
                                                        Average in #REST

                                                          kandi-License License

                                                            summary
                                                            pest is licensed under the MIT License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            pest License
                                                              Best in #REST
                                                                Average in #REST
                                                                pest License
                                                                  Best in #REST
                                                                    Average in #REST

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        pest releases are available to install and integrate.
                                                                        pest Reuse
                                                                          Best in #REST
                                                                            Average in #REST
                                                                            pest Reuse
                                                                              Best in #REST
                                                                                Average in #REST
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed pest and discovered the below as its top functions. This is intended to give you an instant insight into pest implemented functionality, and help decide if they suit your requirements.
                                                                                  • Prints the code coverage .
                                                                                    • Initializes tests .
                                                                                      • Expects a sequence of values .
                                                                                        • Create the suite .
                                                                                          • Remove trace references from the exception .
                                                                                            • Get a value using dot notation .
                                                                                              • Get test file .
                                                                                                • Register the Pest command .
                                                                                                  • Bind a closure to a new closure .
                                                                                                    • Creates a Closure from a Closure .
                                                                                                      Get all kandi verified functions for this library.
                                                                                                      Get all kandi verified functions for this library.

                                                                                                      pest Key Features

                                                                                                      Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.

                                                                                                      pest Examples and Code Snippets

                                                                                                      No Code Snippets are available at this moment for pest.
                                                                                                      Community Discussions

                                                                                                      Trending Discussions on pest

                                                                                                      html and javascript slider working locally but doesn't work in live server
                                                                                                      chevron right
                                                                                                      Having trouble passing lines from txt file to array
                                                                                                      chevron right
                                                                                                      Dynamic reactive objects conflits with observe combined with if
                                                                                                      chevron right
                                                                                                      Plot using subset and/or dplyr:filter doesn't work with dynamic reactive objects
                                                                                                      chevron right
                                                                                                      Check whether String2 is substring of string1 with '*' and '\'
                                                                                                      chevron right
                                                                                                      Shiny observe() function doesn't work with shinymanager
                                                                                                      chevron right
                                                                                                      Use if statement in many reactive objects doesn't work
                                                                                                      chevron right
                                                                                                      Complex function that iterates mvrnorm over rows of a data frame
                                                                                                      chevron right
                                                                                                      i am trying to center my an article with header and list items but the header has been centered but the list items are not properly aligning
                                                                                                      chevron right
                                                                                                      C++, checking two txt files via fstream library to concatenate lines with the same ID
                                                                                                      chevron right

                                                                                                      QUESTION

                                                                                                      html and javascript slider working locally but doesn't work in live server
                                                                                                      Asked 2021-Jun-09 at 05:59

                                                                                                      I have trying to implement a HTML, CSS and Javascript image slider inside my website. I just copy and pest code from w3schools tutorial link. It's working in my local but when I upload it my live server, slider is working but slider image is not showing

                                                                                                      Here is my implemented code below:

                                                                                                              
                                                                                                                  
                                                                                                                      Administrator Features
                                                                                                                      

                                                                                                      Readymade theme administrator features


                                                                                                      My website link is readymadetheme.com

                                                                                                      If you go to console of your browser you will see there 10 404 error with image. I can't understanding why this happening. Do you have any solution for this problem?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jun-09 at 05:55

                                                                                                      Are you sure that those images exist in your live version?

                                                                                                      Currently your mongoDb image displays correctly https://readymadetheme.com/images/mongodb-logo.png

                                                                                                      But your slider images provides 404 error. Meaning the Website can't find them. https://readymadetheme.com/images/slider-img/dashboard.png

                                                                                                      1. Make sure that images exist in the live version.
                                                                                                      2. Try moving slider images to images folder. To check if it works.

                                                                                                      Source https://stackoverflow.com/questions/67898295

                                                                                                      QUESTION

                                                                                                      Having trouble passing lines from txt file to array
                                                                                                      Asked 2021-Jun-08 at 12:02

                                                                                                      I feel like I'm completely missing out on something but my compiler shows absolutely nothing when i test out if my array is getting filled with values from the txt file.

                                                                                                      void orderID(){
                                                                                                        ifstream result;
                                                                                                      
                                                                                                        int flag;
                                                                                                        int loop = 0;
                                                                                                        string temp;
                                                                                                      
                                                                                                        string line;
                                                                                                        string myArray[flag];
                                                                                                      
                                                                                                        result.open("resultat.txt");
                                                                                                        while(getline(result, line)){
                                                                                                          flag++; //number of lines in file
                                                                                                        }
                                                                                                        result.close();
                                                                                                      
                                                                                                        result.open("resultat.txt");
                                                                                                        while(getline(result, line)){
                                                                                                          myArray[loop] = line;
                                                                                                          loop++;
                                                                                                          cout<< myArray[1];
                                                                                                        }
                                                                                                        result.close();
                                                                                                      }
                                                                                                      

                                                                                                      Should probably post the txt file im testing. It should work with any file though.

                                                                                                      21 para 21 first
                                                                                                      23 dyta 23 second
                                                                                                      11 katert 11 fourth
                                                                                                      12 pest 12 fifth
                                                                                                      13 fundit 13 last
                                                                                                      14 jojo 14 nono
                                                                                                      

                                                                                                      Anyone knows what I'm missing here? Btw please do not suggest vectors as I can not use them for this scenario. And yes I am calling the function from int main.

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jun-08 at 11:32

                                                                                                      You need to initialize myArray with the correct size, which means after you compute the flag not while it is undefined

                                                                                                      void orderID(){
                                                                                                        ifstream result;
                                                                                                      
                                                                                                        int flag = 0;
                                                                                                        int loop = 0;
                                                                                                        string temp;
                                                                                                      
                                                                                                        string line;
                                                                                                      
                                                                                                        result.open("resultat.txt");
                                                                                                        while(getline(result, line)){
                                                                                                          flag++; //number of lines in file
                                                                                                        }
                                                                                                        result.close();
                                                                                                      
                                                                                                        string myArray[flag];
                                                                                                      
                                                                                                        result.open("resultat.txt");
                                                                                                        while(getline(result, line)){
                                                                                                          myArray[loop] = line;
                                                                                                          loop++;
                                                                                                          cout<< myArray[1];
                                                                                                        }
                                                                                                        result.close();
                                                                                                      }
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/67886002

                                                                                                      QUESTION

                                                                                                      Dynamic reactive objects conflits with observe combined with if
                                                                                                      Asked 2021-Jun-05 at 23:04

                                                                                                      I try to create an app in Shiny and all selectInput were dynamic reactive objects but at the moment they make some plot (output$myplot) with the combination of the variables select and if(){} condition using observe({}), my plot doesn't work (PEST == unique(stands_ds$PEST) : length of larger object is not multiple of length of smaller object). The problem is with the final selection object selectedvariable4 and try to used selectedvariable4, selectedvariable4(),selectedvariable4()$ID_UNIQUE and unique(selectedvariable4()$ID_UNIQUE) without success. In my example:

                                                                                                      # Packages
                                                                                                      library(rgdal)
                                                                                                      library(shiny)
                                                                                                      library(leaflet)
                                                                                                      library(leaflet.providers)
                                                                                                      library(ggplot2)
                                                                                                      library(shinythemes)
                                                                                                      library(sf)
                                                                                                      library(lubridate)
                                                                                                      library(dplyr)
                                                                                                      library(anytime)
                                                                                                      
                                                                                                      
                                                                                                      # get AOI
                                                                                                      download.file(
                                                                                                        "https://github.com/Leprechault/trash/raw/main/stands_example.zip",
                                                                                                        zip_path <- tempfile(fileext = ".zip")
                                                                                                      )
                                                                                                      unzip(zip_path, exdir = tempdir())
                                                                                                      
                                                                                                      # Open the files
                                                                                                      setwd(tempdir())
                                                                                                      stands_extent <- readOGR(".", "stands_target") # Border
                                                                                                      stands_ds <- read.csv("pred_target_stands.csv", sep=";") # Data set
                                                                                                      stands_ds <- stands_ds %>%
                                                                                                        mutate(DATA_S2 = ymd(DATA_S2))
                                                                                                      stands_ds$PEST<-c(rep("A",34),rep("B",225))
                                                                                                        
                                                                                                      # Create the shiny dash
                                                                                                      ui <- fluidPage(
                                                                                                        theme = shinytheme("cosmo"),
                                                                                                        titlePanel(title="My Map Dashboard"),  
                                                                                                        sidebarLayout(
                                                                                                          sidebarPanel(
                                                                                                            selectInput(inputId = "selectedvariable0", "Type", choices = c(unique(stands_ds$PEST))),
                                                                                                            selectInput(inputId = "selectedvariable1", "Date",choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable2", "Project",choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable3", "Stand",choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable4", "ID-Unique",choices = NULL)
                                                                                                          
                                                                                                          ),
                                                                                                          mainPanel(
                                                                                                            textOutput("idSaida"),
                                                                                                            fluidRow(
                                                                                                              splitLayout(plotOutput("myplot")))
                                                                                                          )
                                                                                                        )
                                                                                                      )
                                                                                                      
                                                                                                      server <- function(input, output, session){
                                                                                                        
                                                                                                        
                                                                                                        selectedvariable0 <- reactive({
                                                                                                          filter(stands_ds, PEST == unique(stands_ds$PEST))
                                                                                                        })
                                                                                                        observeEvent(selectedvariable0(), {
                                                                                                          choices <- anytime::anydate(unique(selectedvariable0()$DATA_S2))
                                                                                                          updateSelectInput(inputId = "selectedvariable1", choices = choices) 
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable1 <- reactive({
                                                                                                          req(input$selectedvariable1)
                                                                                                          filter(selectedvariable0(), DATA_S2 == anytime::anydate(input$selectedvariable1))
                                                                                                        })
                                                                                                        observeEvent(selectedvariable1(), {
                                                                                                          choices <- unique(selectedvariable1()$PROJETO)
                                                                                                          updateSelectInput(inputId = "selectedvariable2", choices = choices)
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable2 <- reactive({
                                                                                                          req(input$selectedvariable2)
                                                                                                          filter(selectedvariable0(), PROJETO == input$selectedvariable2)
                                                                                                        })
                                                                                                        observeEvent(selectedvariable2(), {
                                                                                                          choices <- unique(selectedvariable2()$CD_TALHAO)
                                                                                                          updateSelectInput(inputId = "selectedvariable3", choices = choices)
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable3 <- reactive({
                                                                                                          req(input$selectedvariable3)
                                                                                                          filter(selectedvariable0(), CD_TALHAO == input$selectedvariable3)
                                                                                                        })
                                                                                                        observeEvent(selectedvariable3(), {
                                                                                                          choices <- unique(selectedvariable3()$ID_UNIQUE)
                                                                                                          updateSelectInput(inputId = "selectedvariable4", choices = choices)
                                                                                                        })
                                                                                                        selectedvariable4 <- reactive({
                                                                                                          req(input$selectedvariable4)
                                                                                                          filter(selectedvariable0(), ID_UNIQUE == input$selectedvariable4)
                                                                                                        })
                                                                                                        
                                                                                                        
                                                                                                        #Create plot and maps
                                                                                                        
                                                                                                        observe({
                                                                                                          
                                                                                                          req(selectedvariable0())
                                                                                                          
                                                                                                          if(selectedvariable0()=="B"){
                                                                                                            
                                                                                                            
                                                                                                        output$myplot <- renderPlot({
                                                                                                      
                                                                                                          #Subset stand
                                                                                                          stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==unique(selectedvariable4()$ID_UNIQUE))
                                                                                                      
                                                                                                          #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                          ds_sel<- stands_ds[stands_ds$ID_UNIQUE==unique(selectedvariable4()$ID_UNIQUE),]
                                                                                                      
                                                                                                          #Create a map
                                                                                                          polys <- st_as_sf(stands_sel)
                                                                                                          ggplot() +
                                                                                                            geom_sf(data=polys) +
                                                                                                            geom_point(data=ds_sel,
                                                                                                                       aes(x=X, y=Y), color="red") +
                                                                                                            coord_sf() +
                                                                                                            theme_bw() +
                                                                                                            theme(text = element_text(size=10))
                                                                                                        })
                                                                                                        
                                                                                                          } else {
                                                                                                            
                                                                                                            output$myplot <- renderPlot({
                                                                                                              
                                                                                                              #Subset stand
                                                                                                              stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==unique(selectedvariable4()$ID_UNIQUE))
                                                                                                              
                                                                                                              #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                              ds_sel<- stands_ds[stands_ds$ID_UNIQUE==unique(selectedvariable4()$ID_UNIQUE),]
                                                                                                              
                                                                                                              #Create a map
                                                                                                              polys <- st_as_sf(stands_sel)
                                                                                                              ggplot() +
                                                                                                                geom_sf(data=polys) +
                                                                                                                geom_point(data=ds_sel,
                                                                                                                           aes(x=X, y=Y), color="blue") +
                                                                                                                coord_sf() +
                                                                                                                theme_bw() +
                                                                                                                theme(text = element_text(size=10))
                                                                                                            })
                                                                                                            }
                                                                                                          }) #end of observe function.
                                                                                                       }
                                                                                                      shinyApp(ui, server)
                                                                                                      ##
                                                                                                      

                                                                                                      Please, any help for fix it?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jun-05 at 23:04

                                                                                                      The lines where we are filtering and subset would have == and some of them on the rhs of the operator is unique values i.e. it could be a single value or more than one value. With ==, it is elementwise comparison and it can work only when the rhs object is of length 1 or have the same length as the lhs object. With length 1, it recycles and have no issue, but if the length is more than 1 and not equal to the other object, the recycling will do erroneous output and it may also gives the length warning if the length is not a multiple of the other object.

                                                                                                      It may be safer to use %in% instead. Below is the updated code (not tested though)

                                                                                                      library(rgdal)
                                                                                                      library(shiny)
                                                                                                      library(leaflet)
                                                                                                      library(leaflet.providers)
                                                                                                      library(ggplot2)
                                                                                                      library(shinythemes)
                                                                                                      library(sf)
                                                                                                      library(lubridate)
                                                                                                      library(dplyr)
                                                                                                      library(anytime)
                                                                                                      
                                                                                                      
                                                                                                      # get AOI
                                                                                                      download.file(
                                                                                                        "https://github.com/Leprechault/trash/raw/main/stands_example.zip",
                                                                                                        zip_path <- tempfile(fileext = ".zip")
                                                                                                      )
                                                                                                      unzip(zip_path, exdir = tempdir())
                                                                                                      
                                                                                                      # Open the files
                                                                                                      setwd(tempdir())
                                                                                                      stands_extent <- readOGR(".", "stands_target") # Border
                                                                                                      stands_ds <- read.csv("pred_target_stands.csv", sep=";") # Data set
                                                                                                      stands_ds <- stands_ds %>%
                                                                                                        mutate(DATA_S2 = ymd(DATA_S2))
                                                                                                      stands_ds$PEST<-c(rep("A",34),rep("B",225))
                                                                                                        
                                                                                                      # Create the shiny dash
                                                                                                      ui <- fluidPage(
                                                                                                        theme = shinytheme("cosmo"),
                                                                                                        titlePanel(title="My Map Dashboard"),  
                                                                                                        sidebarLayout(
                                                                                                          sidebarPanel(
                                                                                                            selectInput(inputId = "selectedvariable0", "Type", choices = c(unique(stands_ds$PEST))),
                                                                                                            selectInput(inputId = "selectedvariable1", "Date",choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable2", "Project",choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable3", "Stand",choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable4", "ID-Unique",choices = NULL)
                                                                                                          
                                                                                                          ),
                                                                                                          mainPanel(
                                                                                                            textOutput("idSaida"),
                                                                                                            fluidRow(
                                                                                                              splitLayout(plotOutput("myplot")))
                                                                                                          )
                                                                                                        )
                                                                                                      )
                                                                                                      
                                                                                                      server <- function(input, output, session){
                                                                                                        
                                                                                                        
                                                                                                        selectedvariable0 <- reactive({
                                                                                                          filter(stands_ds, PEST %in% unique(stands_ds$PEST))
                                                                                                        })
                                                                                                        observeEvent(selectedvariable0(), {
                                                                                                          choices <- anytime::anydate(unique(selectedvariable0()$DATA_S2))
                                                                                                          updateSelectInput(inputId = "selectedvariable1", choices = choices) 
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable1 <- reactive({
                                                                                                          req(input$selectedvariable1)
                                                                                                          filter(selectedvariable0(), DATA_S2 %in% anytime::anydate(input$selectedvariable1))
                                                                                                        })
                                                                                                        observeEvent(selectedvariable1(), {
                                                                                                          choices <- unique(selectedvariable1()$PROJETO)
                                                                                                          updateSelectInput(inputId = "selectedvariable2", choices = choices)
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable2 <- reactive({
                                                                                                          req(input$selectedvariable2)
                                                                                                          filter(selectedvariable0(), PROJETO %in% input$selectedvariable2)
                                                                                                        })
                                                                                                        observeEvent(selectedvariable2(), {
                                                                                                          choices <- unique(selectedvariable2()$CD_TALHAO)
                                                                                                          updateSelectInput(inputId = "selectedvariable3", choices = choices)
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable3 <- reactive({
                                                                                                          req(input$selectedvariable3)
                                                                                                          filter(selectedvariable0(), CD_TALHAO %in% input$selectedvariable3)
                                                                                                        })
                                                                                                        observeEvent(selectedvariable3(), {
                                                                                                          choices <- unique(selectedvariable3()$ID_UNIQUE)
                                                                                                          updateSelectInput(inputId = "selectedvariable4", choices = choices)
                                                                                                        })
                                                                                                        selectedvariable4 <- reactive({
                                                                                                          req(input$selectedvariable4)
                                                                                                          filter(selectedvariable0(), ID_UNIQUE %in% input$selectedvariable4)
                                                                                                        })
                                                                                                        
                                                                                                        
                                                                                                        #Create plot and maps
                                                                                                        
                                                                                                        observe({
                                                                                                          
                                                                                                          req(selectedvariable0())
                                                                                                          
                                                                                                          if("B" %in% input$selectedvariable0  ){
                                                                                                            
                                                                                                            
                                                                                                        output$myplot <- renderPlot({
                                                                                                      
                                                                                                          #Subset stand
                                                                                                          stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE %in% unique(selectedvariable4()$ID_UNIQUE))
                                                                                                      
                                                                                                          #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                          ds_sel<- stands_ds[stands_ds$ID_UNIQUE %in% unique(selectedvariable4()$ID_UNIQUE),]
                                                                                                      
                                                                                                          #Create a map
                                                                                                          polys <- st_as_sf(stands_sel)
                                                                                                          ggplot() +
                                                                                                            geom_sf(data=polys) +
                                                                                                            geom_point(data=ds_sel,
                                                                                                                       aes(x=X, y=Y), color="red") +
                                                                                                            coord_sf() +
                                                                                                            theme_bw() +
                                                                                                            theme(text = element_text(size=10))
                                                                                                        })
                                                                                                        
                                                                                                          } else {
                                                                                                            
                                                                                                            output$myplot <- renderPlot({
                                                                                                              
                                                                                                              #Subset stand
                                                                                                              stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE %in% unique(selectedvariable4()$ID_UNIQUE))
                                                                                                              
                                                                                                              #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                              ds_sel<- stands_ds[stands_ds$ID_UNIQUE %in% unique(selectedvariable4()$ID_UNIQUE),]
                                                                                                              
                                                                                                              #Create a map
                                                                                                              polys <- st_as_sf(stands_sel)
                                                                                                              ggplot() +
                                                                                                                geom_sf(data=polys) +
                                                                                                                geom_point(data=ds_sel,
                                                                                                                           aes(x=X, y=Y), color="blue") +
                                                                                                                coord_sf() +
                                                                                                                theme_bw() +
                                                                                                                theme(text = element_text(size=10))
                                                                                                            })
                                                                                                            }
                                                                                                          }) #end of observe function.
                                                                                                       }
                                                                                                      shinyApp(ui, server)
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/67854384

                                                                                                      QUESTION

                                                                                                      Plot using subset and/or dplyr:filter doesn't work with dynamic reactive objects
                                                                                                      Asked 2021-Jun-05 at 21:36

                                                                                                      I try to create an app in Shiny and all selectInput were dynamic reactive objects but at the moment they make some plot (output$myplot) with the combination of the variables select, my plot doesn't work (Error in charToDate: character string is not in a standard unambiguous format). The problem is with the final selection object selectedvariable4 and try to used selectedvariable4, selectedvariable4(),selectedvariable4()$ID_UNIQUE and unique(selectedvariable4()$ID_UNIQUE) without success. In my example:

                                                                                                      # Packages
                                                                                                      library(rgdal)
                                                                                                      library(shiny)
                                                                                                      library(leaflet)
                                                                                                      library(leaflet.providers)
                                                                                                      library(ggplot2)
                                                                                                      library(shinythemes)
                                                                                                      library(sf)
                                                                                                      library(lubridate)
                                                                                                      library(dplyr)
                                                                                                      
                                                                                                      
                                                                                                      # get AOI
                                                                                                      download.file(
                                                                                                        "https://github.com/Leprechault/trash/raw/main/stands_example.zip",
                                                                                                        zip_path <- tempfile(fileext = ".zip")
                                                                                                      )
                                                                                                      unzip(zip_path, exdir = tempdir())
                                                                                                      
                                                                                                      # Open the files
                                                                                                      setwd(tempdir())
                                                                                                      stands_extent <- readOGR(".", "stands_target") # Border
                                                                                                      stands_ds <- read.csv("pred_target_stands.csv", sep=";") # Data set
                                                                                                      stands_ds <- stands_ds %>%
                                                                                                        mutate(DATA_S2 = ymd(DATA_S2))
                                                                                                      
                                                                                                        
                                                                                                      # Create the shiny dash
                                                                                                      ui <- fluidPage(
                                                                                                        theme = shinytheme("cosmo"),
                                                                                                        titlePanel(title="My Map Dashboard"),  
                                                                                                        sidebarLayout(
                                                                                                          sidebarPanel(
                                                                                                            selectInput(inputId = "selectedvariable0", "Type", choices = c(unique(stands_ds$PEST))),
                                                                                                            selectInput(inputId = "selectedvariable1", "Date", choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable2", "Project",choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable3", "Stand",choices = NULL),
                                                                                                            selectInput(inputId = "selectedvariable4", "ID-Unique",choices = NULL)
                                                                                                          
                                                                                                          ),
                                                                                                          mainPanel(
                                                                                                            textOutput("idSaida"),
                                                                                                            fluidRow(
                                                                                                              splitLayout(plotOutput("myplot"))),
                                                                                                            dateInput(inputId = "Dates selection", label = "Time"),
                                                                                                            leafletOutput("map") 
                                                                                                          )
                                                                                                        )
                                                                                                      )
                                                                                                      
                                                                                                      server <- function(input, output, session){
                                                                                                        
                                                                                                        #stands_ds<- reactive({stands_ds})
                                                                                                        
                                                                                                        selectedvariable0 <- reactive({
                                                                                                          filter(stands_ds, PEST == unique(stands_ds$PEST))
                                                                                                        })
                                                                                                        observeEvent(selectedvariable0(), {
                                                                                                          choices <- unique(selectedvariable0()$DATA_S2)
                                                                                                          updateSelectInput(inputId = "selectedvariable1", choices = choices) 
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable1 <- reactive({
                                                                                                          req(input$selectedvariable1)
                                                                                                          filter(selectedvariable0(), DATA_S2 == as.Date(input$selectedvariable1))
                                                                                                        })
                                                                                                        observeEvent(selectedvariable1(), {
                                                                                                          choices <- unique(selectedvariable1()$PROJETO)
                                                                                                          updateSelectInput(inputId = "selectedvariable2", choices = choices)
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable2 <- reactive({
                                                                                                          req(input$selectedvariable2)
                                                                                                          filter(selectedvariable0(), PROJETO == input$selectedvariable2)
                                                                                                        })
                                                                                                        observeEvent(selectedvariable2(), {
                                                                                                          choices <- unique(selectedvariable2()$CD_TALHAO)
                                                                                                          updateSelectInput(inputId = "selectedvariable3", choices = choices)
                                                                                                        })
                                                                                                        
                                                                                                        selectedvariable3 <- reactive({
                                                                                                          req(input$selectedvariable3)
                                                                                                          filter(selectedvariable0(), CD_TALHAO == input$selectedvariable3)
                                                                                                        })
                                                                                                        observeEvent(selectedvariable3(), {
                                                                                                          choices <- unique(selectedvariable3()$ID_UNIQUE)
                                                                                                          updateSelectInput(inputId = "selectedvariable4", choices = choices)
                                                                                                        })
                                                                                                        selectedvariable4 <- reactive({
                                                                                                          req(input$selectedvariable4)
                                                                                                          filter(selectedvariable0(), ID_UNIQUE == input$selectedvariable4)
                                                                                                        })
                                                                                                       
                                                                                                        
                                                                                                        output$myplot <- renderPlot({
                                                                                                      
                                                                                                          #Subset stand
                                                                                                          stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==unique(selectedvariable4()))
                                                                                                      
                                                                                                          #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                          ds_sel<- stands_ds[stands_ds$ID_UNIQUE==unique(selectedvariable4()),]
                                                                                                      
                                                                                                          #Create a map
                                                                                                          polys <- st_as_sf(stands_sel)
                                                                                                          ggplot() +
                                                                                                            geom_sf(data=polys) +
                                                                                                            geom_point(data=ds_sel,
                                                                                                                       aes(x=X, y=Y), color="red") +
                                                                                                            xlab("Longitude") + ylab("Latitude") +
                                                                                                            coord_sf() +
                                                                                                            theme_bw() +
                                                                                                            theme(text = element_text(size=10))
                                                                                                        })
                                                                                                      
                                                                                                        output$map <- renderLeaflet({
                                                                                                      
                                                                                                          stands_actual<-stands_ds[stands_ds$ID_UNIQUE==unique(selectedvariable4()),]
                                                                                                          lng <- mean(stands_actual$X)
                                                                                                          lat <- mean(stands_actual$Y)
                                                                                                      
                                                                                                          leaflet() %>%
                                                                                                            setView(lng = lng, lat = lat, zoom=17) %>%
                                                                                                            addProviderTiles(providers$Esri.WorldImagery) %>%
                                                                                                            addMarkers(lng=stands_actual$X, lat=stands_actual$Y, popup="Location")
                                                                                                      
                                                                                                        })
                                                                                                       }
                                                                                                      shinyApp(ui, server)
                                                                                                      ##
                                                                                                      

                                                                                                      Please, any help for fix it?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jun-05 at 21:36

                                                                                                      The error mentioned in the OP's post is due to applying as.Date directly without any specificiation of format. By default, the format it uses is %Y-%m-%d i.e. YYYY-MM-DD. If the input format is anything else, it throws the error as below

                                                                                                      as.Date("12/24/2023")
                                                                                                      #Error in charToDate(x) : 
                                                                                                      #  character string is not in a standard unambiguous format
                                                                                                      

                                                                                                      Here we need

                                                                                                      as.Date("12/24/2023", format = '%m/%d/%Y')
                                                                                                      #[1] "2023-12-24"
                                                                                                      

                                                                                                      In the OP's post it is not clear about the format. One option to automatically detect the format is with anydate from anytime

                                                                                                      ...
                                                                                                      library(anytime)
                                                                                                      filter(selectedvariable0(), DATA_S2 == anydate(input$selectedvariable1))
                                                                                                      ...
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/67853872

                                                                                                      QUESTION

                                                                                                      Check whether String2 is substring of string1 with '*' and '\'
                                                                                                      Asked 2021-Jun-04 at 13:40

                                                                                                      Given two strings s1 and s2, we have to check if s2 is a substring of s1. If it's true print "true" else print "false" But s1 and s2 can contain characters like '*' and '\'. In s2, '*' represents zero or more characters in between two alphabets and '\' represents an escape sequence for '*'. In s1, '*' and '\' are just other characters that are to be checked.

                                                                                                      Sample Input and Output:

                                                                                                      Input: abcd , a*c   Output: true
                                                                                                      Input : spoon , sp*n  Output : true
                                                                                                      Input : regex , re*g    Output : true
                                                                                                      Input : search , *c Output : true
                                                                                                      Input : zoho , *o*o Output : true
                                                                                                      Input : zoho , *ogo Output : false
                                                                                                      Input : test , pest Output : false
                                                                                                      Input : st*r , t\*r Output : true
                                                                                                      Input : star , t\*r Output false
                                                                                                      Input : tree , tr\  Output false
                                                                                                      Input : tr\e , tr\  Output true
                                                                                                      

                                                                                                      I know this question can be solved easily by using regex, but I need a logical approach for solving this. Can anybody help me soon? Below is my code that I have tried, but couldn't solve entirely.

                                                                                                      public static void main(String[] args)
                                                                                                          {
                                                                                                              Scanner sc = new Scanner(System.in);
                                                                                                              String s1 = sc.next();
                                                                                                              String s2 = sc.next();
                                                                                                              boolean flag = true;
                                                                                                              int i=0,j=0;
                                                                                                              for(;s2.charAt(j)<'a' || s2.charAt(j)>'z';j++);
                                                                                                              
                                                                                                              for(i=0;i122)
                                                                                                                      {
                                                                                                                          flag = false;
                                                                                                                          break;
                                                                                                                      }
                                                                                                                  }
                                                                                                              System.out.print(flag);
                                                                                                              
                                                                                                          }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jun-04 at 05:06

                                                                                                      I'm not sure what what you mean with the * and the /, but, one solution to know if a string is a substring for another one is using "contains" method, that extends from String class:

                                                                                                      public static void main(String[] args) {
                                                                                                          String str1 = "abcdefghi";
                                                                                                          String str2 = "abcd";
                                                                                                          
                                                                                                          if (str1.contains(str2)) {
                                                                                                              System.out.println("Exist the substring.");
                                                                                                          } else {
                                                                                                              System.out.println("Not exist.");
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      I'm thinking that you also needs to replace if exist * or / as a valid value

                                                                                                      Source https://stackoverflow.com/questions/67831626

                                                                                                      QUESTION

                                                                                                      Shiny observe() function doesn't work with shinymanager
                                                                                                      Asked 2021-Jun-03 at 04:53

                                                                                                      I have an if statement condition for my plots and I need to use observe function. All the app works OK, but when I try to use the shinymanager for credentials creation, my app doesn't work anymore and the error is always: Error in if: argument has length zero

                                                                                                      library(leaflet)
                                                                                                      library(leaflet.providers)
                                                                                                      library(ggplot2)
                                                                                                      library(shinythemes)
                                                                                                      library(sf)
                                                                                                      library(lubridate)
                                                                                                      library(dplyr)
                                                                                                      library(rgdal)
                                                                                                      library(rgeos)
                                                                                                      require(shinymanager)
                                                                                                      
                                                                                                      # Create credentials
                                                                                                      credentials <- data.frame(
                                                                                                         user = c("test","manager"), # mandatory
                                                                                                         password = c("654321"), # mandatory
                                                                                                         start = c("2021-05-15","123456"), # optinal (all others)
                                                                                                         expire = c(NA, "2022-12-31"),
                                                                                                         admin = c(FALSE, TRUE),
                                                                                                         comment = "Simple and secure authentification mechanism 
                                                                                                         for single ‘Shiny’ applications.",
                                                                                                         stringsAsFactors = FALSE
                                                                                                       )
                                                                                                      
                                                                                                      # get AOI
                                                                                                      download.file(
                                                                                                        "https://github.com/Leprechault/trash/raw/main/stands_example.zip",
                                                                                                        zip_path <- tempfile(fileext = ".zip")
                                                                                                      )
                                                                                                      unzip(zip_path, exdir = tempdir())
                                                                                                      
                                                                                                      # Open the files
                                                                                                      setwd(tempdir())
                                                                                                      stands_extent <- readOGR(".", "stands_target") # Border
                                                                                                      stands_ds <- read.csv("pred_target_stands.csv", sep=";") # Data set
                                                                                                      stands_ds <- stands_ds %>%
                                                                                                        mutate(DATA_S2 = ymd(DATA_S2))
                                                                                                      stands_ds$CLASS<-c(rep("A",129),rep("B",130)) 
                                                                                                      stands_ds$CD<-abs(rnorm(length(stands_ds[,1]),mean=50))
                                                                                                      
                                                                                                      # Create the shiny dash
                                                                                                      ui <- fluidPage(
                                                                                                        theme = shinytheme("cosmo"),
                                                                                                        titlePanel(title="My Map Dashboard"),  
                                                                                                        sidebarLayout(
                                                                                                          sidebarPanel(
                                                                                                            selectInput(inputId = "selectedvariable0",
                                                                                                                        label = "Type", 
                                                                                                                        choices = c(unique(stands_ds$PEST)),selected = TRUE ), 
                                                                                                            selectInput(inputId = "selectedvariable1",
                                                                                                                        label = "Date", 
                                                                                                                        choices = c(unique(stands_ds$DATA_S)),selected = TRUE ), 
                                                                                                            selectInput(inputId = "selectedvariable2",
                                                                                                                        label = "Project", 
                                                                                                                        choices = c(unique(stands_ds$PROJETO)),selected = TRUE ),
                                                                                                            selectInput(inputId = "selectedvariable3",
                                                                                                                        label = "Stand", 
                                                                                                                        choices = c(unique(stands_ds$CD_TALHAO)),selected = TRUE),
                                                                                                            selectInput(inputId = "selectedvariable4",
                                                                                                                        label = "Unique ID", 
                                                                                                                        choices = c(unique(stands_ds$ID_UNIQUE)),selected = TRUE),
                                                                                                            selectInput(inputId = "selectedvariable5",
                                                                                                                        label = "Class", 
                                                                                                                        choices = c(unique(stands_ds$CLASS)),selected = TRUE)            
                                                                                                          ),
                                                                                                          mainPanel(
                                                                                                            textOutput("idSaida"),
                                                                                                            fluidRow(
                                                                                                              splitLayout(plotOutput("myplot"))),
                                                                                                            dateInput(inputId = "Dates selection", label = "Time"),
                                                                                                            leafletOutput("map") 
                                                                                                          )
                                                                                                        )
                                                                                                      )
                                                                                                      ui <- secure_app(ui)
                                                                                                      
                                                                                                      
                                                                                                      server <- function(input, output, session){
                                                                                                        
                                                                                                        # # check_credentials returns a function to authenticate users
                                                                                                         res_auth <- secure_server(
                                                                                                           check_credentials = check_credentials(credentials)
                                                                                                         )
                                                                                                        
                                                                                                        
                                                                                                        currentvariable0 <- reactive({input$selectedvariable0})
                                                                                                        currentvariable1 <- reactive({input$selectedvariable1})
                                                                                                        currentvariable2 <- reactive({input$selectedvariable2})
                                                                                                        currentvariable3 <- reactive({input$selectedvariable3})
                                                                                                        currentvariable4 <- reactive({input$selectedvariable4})
                                                                                                        currentvariable5 <- reactive({input$selectedvariable5})
                                                                                                        
                                                                                                        observe({ 
                                                                                                          if(currentvariable5()=="A"){
                                                                                                            
                                                                                                            
                                                                                                            output$myplot <- renderPlot({
                                                                                                              
                                                                                                              #Subset stand
                                                                                                              stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==currentvariable4())
                                                                                                              
                                                                                                              #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                              ds_sel<- stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                              
                                                                                                              #Create a map
                                                                                                              polys <- st_as_sf(stands_sel)
                                                                                                              ggplot() +
                                                                                                                geom_sf(data=polys) +
                                                                                                                geom_point(data=ds_sel,
                                                                                                                           aes(x=X, y=Y), color="red") +
                                                                                                                xlab("Longitude") + ylab("Latitude") +
                                                                                                                coord_sf() +
                                                                                                                theme_bw() +
                                                                                                                theme(text = element_text(size=10)) 
                                                                                                            })
                                                                                                          } else {
                                                                                                            
                                                                                                            #Subset stand
                                                                                                            stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==currentvariable4())
                                                                                                            
                                                                                                            #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                            ds_sel<- stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                            
                                                                                                            #Create a map
                                                                                                            polys <- st_as_sf(stands_sel)
                                                                                                            ggplot() +
                                                                                                              geom_sf(data=polys) +
                                                                                                              geom_raster(data = stands_sel, aes(x = X, y = Y, fill = CD)) + 
                                                                                                              scale_fill_gradientn(name="Desfolha (%)",colours = terrain.colors(100))+
                                                                                                              xlab("Longitude") + ylab("Latitude") +
                                                                                                              coord_sf() +
                                                                                                              theme_bw() +
                                                                                                              theme(text = element_text(size=10)) 
                                                                                                            
                                                                                                          }
                                                                                                          
                                                                                                          output$map <- renderLeaflet({
                                                                                                            
                                                                                                            stands_actual<-stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                            lng <- mean(stands_actual$X)
                                                                                                            lat <- mean(stands_actual$Y)
                                                                                                            
                                                                                                            leaflet() %>%
                                                                                                              setView(lng = lng, lat = lat, zoom=17) %>%
                                                                                                              addProviderTiles(providers$Esri.WorldImagery) %>%                   
                                                                                                              addMarkers(lng=stands_actual$X, lat=stands_actual$Y, popup="Location")
                                                                                                            
                                                                                                          }) }) #end of observe function.
                                                                                                      }
                                                                                                      shinyApp(ui, server)
                                                                                                      

                                                                                                      Please, any help to fix it?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jun-03 at 04:53

                                                                                                      You can add a req check in observe -

                                                                                                      observe({ 
                                                                                                          req(currentvariable5())
                                                                                                          if(currentvariable5()=="A"){
                                                                                                          #....
                                                                                                          #....
                                                                                                          #....
                                                                                                          }
                                                                                                      })
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/67814726

                                                                                                      QUESTION

                                                                                                      Use if statement in many reactive objects doesn't work
                                                                                                      Asked 2021-Jun-02 at 22:10

                                                                                                      I'd like to use my currentvariable5() reactive object to create some kind of plot if == "A" ( if(currentvariable5()=="A"){}) and another if == "B" (else{}). But I try many tricks in several posts and the output is always:

                                                                                                      Warning: Error in : Operation not allowed without an active reactive context.
                                                                                                      * You tried to do something that can only be done from inside a reactive consumer.
                                                                                                        55: 
                                                                                                      Error : Operation not allowed without an active reactive context.
                                                                                                      * You tried to do something that can only be done from inside a reactive consumer.
                                                                                                      

                                                                                                      This is my example:

                                                                                                      library(leaflet)
                                                                                                      library(leaflet.providers)
                                                                                                      library(ggplot2)
                                                                                                      library(shinythemes)
                                                                                                      library(sf)
                                                                                                      library(lubridate)
                                                                                                      library(dplyr)
                                                                                                      library(rgdal)
                                                                                                      
                                                                                                      
                                                                                                      # get AOI
                                                                                                      download.file(
                                                                                                        "https://github.com/Leprechault/trash/raw/main/stands_example.zip",
                                                                                                        zip_path <- tempfile(fileext = ".zip")
                                                                                                      )
                                                                                                      unzip(zip_path, exdir = tempdir())
                                                                                                      
                                                                                                      # Open the files
                                                                                                      setwd(tempdir())
                                                                                                      stands_extent <- readOGR(".", "stands_target") # Border
                                                                                                      stands_ds <- read.csv("pred_target_stands.csv", sep=";") # Data set
                                                                                                      stands_ds <- stands_ds %>%
                                                                                                        mutate(DATA_S2 = ymd(DATA_S2))
                                                                                                      stands_ds$CLASS<-c(rep("A",129),rep("B",130)) 
                                                                                                      stands_ds$CD<-abs(rnorm(length(stands_ds[,1]),mean=50))
                                                                                                      
                                                                                                      # Create the shiny dash
                                                                                                      ui <- fluidPage(
                                                                                                        theme = shinytheme("cosmo"),
                                                                                                        titlePanel(title="My Map Dashboard"),  
                                                                                                        sidebarLayout(
                                                                                                          sidebarPanel(
                                                                                                            selectInput(inputId = "selectedvariable0",
                                                                                                                        label = "Type", 
                                                                                                                        choices = c(unique(stands_ds$PEST)),selected = TRUE ), 
                                                                                                            selectInput(inputId = "selectedvariable1",
                                                                                                                        label = "Date", 
                                                                                                                        choices = c(unique(stands_ds$DATA_S)),selected = TRUE ), 
                                                                                                            selectInput(inputId = "selectedvariable2",
                                                                                                                        label = "Project", 
                                                                                                                        choices = c(unique(stands_ds$PROJETO)),selected = TRUE ),
                                                                                                            selectInput(inputId = "selectedvariable3",
                                                                                                                        label = "Stand", 
                                                                                                                        choices = c(unique(stands_ds$CD_TALHAO)),selected = TRUE),
                                                                                                            selectInput(inputId = "selectedvariable4",
                                                                                                                        label = "Unique ID", 
                                                                                                                        choices = c(unique(stands_ds$ID_UNIQUE)),selected = TRUE),
                                                                                                            selectInput(inputId = "selectedvariable5",
                                                                                                                        label = "Class", 
                                                                                                                        choices = c(unique(stands_ds$CLASS)),selected = TRUE)            
                                                                                                          ),
                                                                                                          mainPanel(
                                                                                                            textOutput("idSaida"),
                                                                                                            fluidRow(
                                                                                                              splitLayout(plotOutput("myplot"))),
                                                                                                            dateInput(inputId = "Dates selection", label = "Time"),
                                                                                                            leafletOutput("map") 
                                                                                                          )
                                                                                                        )
                                                                                                      )
                                                                                                      server <- function(input, output){
                                                                                                        
                                                                                                        currentvariable0 <- reactive({input$selectedvariable0})
                                                                                                        currentvariable1 <- reactive({input$selectedvariable1})
                                                                                                        currentvariable2 <- reactive({input$selectedvariable2})
                                                                                                        currentvariable3 <- reactive({input$selectedvariable3})
                                                                                                        currentvariable4 <- reactive({input$selectedvariable4})
                                                                                                        currentvariable5 <- reactive({input$selectedvariable5})
                                                                                                        
                                                                                                        if(currentvariable5()=="A"){
                                                                                                          
                                                                                                          
                                                                                                          output$myplot <- renderPlot({
                                                                                                            
                                                                                                            #Subset stand
                                                                                                            stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==currentvariable4())
                                                                                                            
                                                                                                            #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                            ds_sel<- stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                            
                                                                                                            #Create a map
                                                                                                            polys <- st_as_sf(stands_sel)
                                                                                                            ggplot() +
                                                                                                              geom_sf(data=polys) +
                                                                                                              geom_point(data=ds_sel,
                                                                                                                         aes(x=X, y=Y), color="red") +
                                                                                                              xlab("Longitude") + ylab("Latitude") +
                                                                                                              coord_sf() +
                                                                                                              theme_bw() +
                                                                                                              theme(text = element_text(size=10)) 
                                                                                                          })
                                                                                                        } else {
                                                                                                          
                                                                                                          #Subset stand
                                                                                                          stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==currentvariable4())
                                                                                                          
                                                                                                          #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                          ds_sel<- stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                          
                                                                                                          #Create a map
                                                                                                          polys <- st_as_sf(stands_sel)
                                                                                                          ggplot() +
                                                                                                            geom_sf(data=polys) +
                                                                                                            geom_raster(data = stands_sel, aes(x = X, y = Y, fill = CD)) + 
                                                                                                            scale_fill_gradientn(name="Desfolha (%)",colours = terrain.colors(100))+
                                                                                                            xlab("Longitude") + ylab("Latitude") +
                                                                                                            coord_sf() +
                                                                                                            theme_bw() +
                                                                                                            theme(text = element_text(size=10)) 
                                                                                                          
                                                                                                        }
                                                                                                        
                                                                                                        output$map <- renderLeaflet({
                                                                                                          
                                                                                                          stands_actual<-stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                          lng <- mean(stands_actual$X)
                                                                                                          lat <- mean(stands_actual$Y)
                                                                                                          
                                                                                                          leaflet() %>%
                                                                                                            setView(lng = lng, lat = lat, zoom=17) %>%
                                                                                                            addProviderTiles(providers$Esri.WorldImagery) %>%                   
                                                                                                            addMarkers(lng=stands_actual$X, lat=stands_actual$Y, popup="Location")
                                                                                                          
                                                                                                        })   
                                                                                                      }
                                                                                                      shinyApp(ui, server)
                                                                                                      ##
                                                                                                      

                                                                                                      Please, any tip for solve this? Thanks in advance!!!

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jun-02 at 22:10

                                                                                                      We can wrap the if-else statements in observe(). The reason reactive() is not called is because we are actually interested in the side effects here (eg declaring output$myplot. Also, a reactive (observe, reactive, eventReactive observeEvent) context is recommended whenever an input$.. is called because it's intended to change upon user's input.

                                                                                                      library(leaflet)
                                                                                                      library(leaflet.providers)
                                                                                                      library(ggplot2)
                                                                                                      library(shinythemes)
                                                                                                      library(sf)
                                                                                                      library(lubridate)
                                                                                                      library(dplyr)
                                                                                                      library(rgdal)
                                                                                                      library(rgeos)
                                                                                                      
                                                                                                      # get AOI
                                                                                                      download.file(
                                                                                                          "https://github.com/Leprechault/trash/raw/main/stands_example.zip",
                                                                                                          zip_path <- tempfile(fileext = ".zip")
                                                                                                      )
                                                                                                      unzip(zip_path, exdir = tempdir())
                                                                                                      
                                                                                                      # Open the files
                                                                                                      setwd(tempdir())
                                                                                                      stands_extent <- readOGR(".", "stands_target") # Border
                                                                                                      stands_ds <- read.csv("pred_target_stands.csv", sep=";") # Data set
                                                                                                      stands_ds <- stands_ds %>%
                                                                                                          mutate(DATA_S2 = ymd(DATA_S2))
                                                                                                      stands_ds$CLASS<-c(rep("A",129),rep("B",130)) 
                                                                                                      stands_ds$CD<-abs(rnorm(length(stands_ds[,1]),mean=50))
                                                                                                      
                                                                                                      # Create the shiny dash
                                                                                                      ui <- fluidPage(
                                                                                                          theme = shinytheme("cosmo"),
                                                                                                          titlePanel(title="My Map Dashboard"),  
                                                                                                          sidebarLayout(
                                                                                                              sidebarPanel(
                                                                                                                  selectInput(inputId = "selectedvariable0",
                                                                                                                              label = "Type", 
                                                                                                                              choices = c(unique(stands_ds$PEST)),selected = TRUE ), 
                                                                                                                  selectInput(inputId = "selectedvariable1",
                                                                                                                              label = "Date", 
                                                                                                                              choices = c(unique(stands_ds$DATA_S)),selected = TRUE ), 
                                                                                                                  selectInput(inputId = "selectedvariable2",
                                                                                                                              label = "Project", 
                                                                                                                              choices = c(unique(stands_ds$PROJETO)),selected = TRUE ),
                                                                                                                  selectInput(inputId = "selectedvariable3",
                                                                                                                              label = "Stand", 
                                                                                                                              choices = c(unique(stands_ds$CD_TALHAO)),selected = TRUE),
                                                                                                                  selectInput(inputId = "selectedvariable4",
                                                                                                                              label = "Unique ID", 
                                                                                                                              choices = c(unique(stands_ds$ID_UNIQUE)),selected = TRUE),
                                                                                                                  selectInput(inputId = "selectedvariable5",
                                                                                                                              label = "Class", 
                                                                                                                              choices = c(unique(stands_ds$CLASS)),selected = TRUE)            
                                                                                                              ),
                                                                                                              mainPanel(
                                                                                                                  textOutput("idSaida"),
                                                                                                                  fluidRow(
                                                                                                                      splitLayout(plotOutput("myplot"))),
                                                                                                                  dateInput(inputId = "Dates selection", label = "Time"),
                                                                                                                  leafletOutput("map") 
                                                                                                              )
                                                                                                          )
                                                                                                      )
                                                                                                      server <- function(input, output){
                                                                                                          
                                                                                                          currentvariable0 <- reactive({input$selectedvariable0})
                                                                                                          currentvariable1 <- reactive({input$selectedvariable1})
                                                                                                          currentvariable2 <- reactive({input$selectedvariable2})
                                                                                                          currentvariable3 <- reactive({input$selectedvariable3})
                                                                                                          currentvariable4 <- reactive({input$selectedvariable4})
                                                                                                          currentvariable5 <- reactive({input$selectedvariable5})
                                                                                                       
                                                                                                      observe({ 
                                                                                                          if(currentvariable5()=="A"){
                                                                                                              
                                                                                                              
                                                                                                              output$myplot <- renderPlot({
                                                                                                                  
                                                                                                                  #Subset stand
                                                                                                                  stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==currentvariable4())
                                                                                                                  
                                                                                                                  #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                                  ds_sel<- stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                                  
                                                                                                                  #Create a map
                                                                                                                  polys <- st_as_sf(stands_sel)
                                                                                                                  ggplot() +
                                                                                                                      geom_sf(data=polys) +
                                                                                                                      geom_point(data=ds_sel,
                                                                                                                                 aes(x=X, y=Y), color="red") +
                                                                                                                      xlab("Longitude") + ylab("Latitude") +
                                                                                                                      coord_sf() +
                                                                                                                      theme_bw() +
                                                                                                                      theme(text = element_text(size=10)) 
                                                                                                              })
                                                                                                          } else {
                                                                                                              
                                                                                                              #Subset stand
                                                                                                              stands_sel <- subset(stands_extent, stands_extent@data$ID_UNIQUE==currentvariable4())
                                                                                                              
                                                                                                              #Subset for input$var and assign this subset to new object, "fbar"
                                                                                                              ds_sel<- stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                              
                                                                                                              #Create a map
                                                                                                              polys <- st_as_sf(stands_sel)
                                                                                                              ggplot() +
                                                                                                                  geom_sf(data=polys) +
                                                                                                                  geom_raster(data = stands_sel, aes(x = X, y = Y, fill = CD)) + 
                                                                                                                  scale_fill_gradientn(name="Desfolha (%)",colours = terrain.colors(100))+
                                                                                                                  xlab("Longitude") + ylab("Latitude") +
                                                                                                                  coord_sf() +
                                                                                                                  theme_bw() +
                                                                                                                  theme(text = element_text(size=10)) 
                                                                                                              
                                                                                                          }
                                                                                                          
                                                                                                          output$map <- renderLeaflet({
                                                                                                              
                                                                                                              stands_actual<-stands_ds[stands_ds$ID_UNIQUE==currentvariable4(),]
                                                                                                              lng <- mean(stands_actual$X)
                                                                                                              lat <- mean(stands_actual$Y)
                                                                                                              
                                                                                                              leaflet() %>%
                                                                                                                  setView(lng = lng, lat = lat, zoom=17) %>%
                                                                                                                  addProviderTiles(providers$Esri.WorldImagery) %>%                   
                                                                                                                  addMarkers(lng=stands_actual$X, lat=stands_actual$Y, popup="Location")
                                                                                                              
                                                                                                          }) }) #end of observe function.
                                                                                                      }
                                                                                                      shinyApp(ui, server)
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/67811463

                                                                                                      QUESTION

                                                                                                      Complex function that iterates mvrnorm over rows of a data frame
                                                                                                      Asked 2021-Jun-01 at 22:07

                                                                                                      I have data that looks like this:

                                                                                                      data = data.frame(a.coef = c(.14, .15, .16), 
                                                                                                                        b.coef = c(.4, .5, .6), 
                                                                                                                        a.var = c(0.0937, 0.0934, 0.0945), 
                                                                                                                        b.var = c(0.00453, 0.00564, 0.00624), 
                                                                                                                        ab.cov = c(0.000747, 0.000747, 0.000747))
                                                                                                      

                                                                                                      and I would like to run the following code (source: http://www.quantpsy.org/medmc/medmc.htm) on each row of the data set.

                                                                                                      require(MASS)
                                                                                                      a = data$a.coef
                                                                                                      b = data$b.coef
                                                                                                      rep = 10000
                                                                                                      conf = 95
                                                                                                      pest = c(a, b)
                                                                                                      acov <- matrix(c(data$a.var, data$ab.cov, 
                                                                                                                       data$ab.cov, data$b.var), 2, 2)
                                                                                                      mcmc <- mvrnorm(rep, pest, acov, empirical = FALSE)
                                                                                                      ab <- mcmc[ , 1] * mcmc[ , 2]
                                                                                                      low = (1 - conf / 100) / 2
                                                                                                      upp = ((1 - conf / 100) / 2) + (conf / 100)
                                                                                                      LL = quantile(ab, low)
                                                                                                      UL = quantile(ab, upp)
                                                                                                      LL4 = format(LL, digits = 4)
                                                                                                      UL4 = format(UL, digits = 4)
                                                                                                      

                                                                                                      I've created a relatively simple function that takes the data and the row number as inputs:

                                                                                                      MCMAM <- function(data_input, row_number) {
                                                                                                        data = data_input[row_number, ]
                                                                                                        a = data[["a.coef"]]
                                                                                                        b = data[["b.coef"]]
                                                                                                        rep = 10000
                                                                                                        conf = 95
                                                                                                        pest = c(a, b)
                                                                                                        acov <- matrix(c(data[["a.var"]], data[["ab.cov"]], 
                                                                                                                         data[["ab.cov"]], data[["b.var"]]), 2, 2)
                                                                                                        require(MASS)
                                                                                                        mcmc <- mvrnorm(rep, pest, acov, empirical = FALSE)
                                                                                                        ab <- mcmc[, 1] * mcmc[, 2]
                                                                                                        low = (1 - conf / 100) / 2
                                                                                                        upp = ((1 - conf / 100) / 2) + (conf / 100)
                                                                                                        LL = quantile(ab, low)
                                                                                                        UL = quantile(ab, upp)
                                                                                                        return(c(LL, UL))
                                                                                                      }
                                                                                                      
                                                                                                      MCMAM(data, 1)
                                                                                                      
                                                                                                          2.5%      97.5% 
                                                                                                      -0.1901272  0.3104614 
                                                                                                      

                                                                                                      But it would be great if there was a way to get rid of the row specification and just have the function run through the data set row by row and save the output to a new column in the data set.

                                                                                                      I've been experimenting with for loops and apply functions but haven't had any success, largely because both the matrix() and mvrnorm() functions take values rather than vectors.

                                                                                                      ANSWER

                                                                                                      Answered 2021-Jun-01 at 22:07

                                                                                                      We can use lapply

                                                                                                      do.call(rbind, lapply(seq_len(nrow(data)), MCMAM, data_input = data))
                                                                                                      

                                                                                                      -ouptut

                                                                                                          2.5%     97.5%
                                                                                                      [1,] -0.1832449 0.3098362
                                                                                                      [2,] -0.2260856 0.3856575
                                                                                                      [3,] -0.2521126 0.4666583
                                                                                                      

                                                                                                      Or use rowwise

                                                                                                      library(dplyr)
                                                                                                      library(tidyr)
                                                                                                      data %>% 
                                                                                                           rowwise %>% 
                                                                                                           mutate(new = list(MCMAM(cur_data(), 1))) %>%
                                                                                                           unnest_wider(new)
                                                                                                      # A tibble: 3 x 7
                                                                                                      #  a.coef b.coef  a.var   b.var   ab.cov `2.5%` `97.5%`
                                                                                                      #                   
                                                                                                      #1   0.14    0.4 0.0937 0.00453 0.000747 -0.185   0.309
                                                                                                      #2   0.15    0.5 0.0934 0.00564 0.000747 -0.219   0.396
                                                                                                      #3   0.16    0.6 0.0945 0.00624 0.000747 -0.259   0.472
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/67796552

                                                                                                      QUESTION

                                                                                                      i am trying to center my an article with header and list items but the header has been centered but the list items are not properly aligning
                                                                                                      Asked 2021-May-31 at 18:01

                                                                                                      [image showing what I need to create

                                                                                                              Here's a time line of Dr. Borlaug's life:
                                                                                                              
                                                                                                        
                                                                                                      • 1914 - Born in Cresco, Iowa
                                                                                                      • 1933 - Leaves his family's farm to attend the University of Minnesota, thanks to a Depression era program known as the "National Youth Administration"
                                                                                                      • 1935 - Has to stop school and save up more money. Works in the Civilian Conservation Corps, helping starving Americans. "I saw how food changed them", he said. "All of this left scars on me."
                                                                                                      • 1937 - Finishes university and takes a job in the US Forestry Service
                                                                                                      • 1938 - Marries wife of 69 years Margret Gibson. Gets laid off due to budget cuts. Inspired by Elvin Charles Stakman, he returns to school study under Stakman, who teaches him about breeding pest-resistent plants.
                                                                                                      • 1941 - Tries to enroll in the military after the Pearl Harbor attack, but is rejected. Instead, the military asked his lab to work on waterproof glue, DDT to control malaria, disinfectants, and other applied science.
                                                                                                      • 1942 - Receives a Ph.D. in Genetics and Plant Pathology
                                                                                                      • 1944 - Rejects a 100% salary increase from Dupont, leaves behind his pregnant wife, and flies to Mexico to head a new plant pathology program. Over the next 16 years, his team breeds 6,000 different strains of disease resistent wheat - including different varieties for each major climate on Earth.
                                                                                                      • 1945 - Discovers a way to grown wheat twice each season, doubling wheat yields
                                                                                                      • 1953 - crosses a short, sturdy dwarf breed of wheat with a high-yeidling American breed, creating a strain that responds well to fertilizer. It goes on to provide 95% of Mexico's wheat.
                                                                                                      • 1962 - Visits Delhi and brings his high-yielding strains of wheat to the Indian subcontinent in time to help mitigate mass starvation due to a rapidly expanding population
                                                                                                      • 1970 - receives the Nobel Peace Prize
                                                                                                      • 1983 - helps seven African countries dramatically increase their maize and sorghum yields
                                                                                                      • 1984 - becomes a distinguished professor at Texas A&M University
                                                                                                      • 2005 - states "we will have to double the world food supply by 2050." Argues that genetically modified crops are the only way we can meet the demand, as we run out of arable land. Says that GM crops are not inherently dangerous because "we've been genetically modifying plants and animals for a long time. Long before we called it science, people were selecting the best breeds."
                                                                                                      • 2009 - dies at the age of 95.

                                                                                                      ]1

                                                                                                      I need help to center the header and list items to look like the image posted

                                                                                                      ANSWER

                                                                                                      Answered 2021-May-31 at 17:55

                                                                                                      h2 {
                                                                                                          width: fit-content;
                                                                                                          margin: auto;
                                                                                                       }
                                                                                                      Here's a time line of Dr. Borlaug's life:
                                                                                                              
                                                                                                        
                                                                                                      • 1914 - Born in Cresco, Iowa
                                                                                                      • 1933 - Leaves his family's farm to attend the University of Minnesota, thanks to a Depression era program known as the "National Youth Administration"
                                                                                                      • 1935 - Has to stop school and save up more money. Works in the Civilian Conservation Corps, helping starving Americans. "I saw how food changed them", he said. "All of this left scars on me."
                                                                                                      • 1937 - Finishes university and takes a job in the US Forestry Service
                                                                                                      • 1938 - Marries wife of 69 years Margret Gibson. Gets laid off due to budget cuts. Inspired by Elvin Charles Stakman, he returns to school study under Stakman, who teaches him about breeding pest-resistent plants.
                                                                                                      • 1941 - Tries to enroll in the military after the Pearl Harbor attack, but is rejected. Instead, the military asked his lab to work on waterproof glue, DDT to control malaria, disinfectants, and other applied science.
                                                                                                      • 1942 - Receives a Ph.D. in Genetics and Plant Pathology
                                                                                                      • 1944 - Rejects a 100% salary increase from Dupont, leaves behind his pregnant wife, and flies to Mexico to head a new plant pathology program. Over the next 16 years, his team breeds 6,000 different strains of disease resistent wheat - including different varieties for each major climate on Earth.
                                                                                                      • 1945 - Discovers a way to grown wheat twice each season, doubling wheat yields
                                                                                                      • 1953 - crosses a short, sturdy dwarf breed of wheat with a high-yeidling American breed, creating a strain that responds well to fertilizer. It goes on to provide 95% of Mexico's wheat.
                                                                                                      • 1962 - Visits Delhi and brings his high-yielding strains of wheat to the Indian subcontinent in time to help mitigate mass starvation due to a rapidly expanding population
                                                                                                      • 1970 - receives the Nobel Peace Prize
                                                                                                      • 1983 - helps seven African countries dramatically increase their maize and sorghum yields
                                                                                                      • 1984 - becomes a distinguished professor at Texas A&M University
                                                                                                      • 2005 - states "we will have to double the world food supply by 2050." Argues that genetically modified crops are the only way we can meet the demand, as we run out of arable land. Says that GM crops are not inherently dangerous because "we've been genetically modifying plants and animals for a long time. Long before we called it science, people were selecting the best breeds."
                                                                                                      • 2009 - dies at the age of 95.

                                                                                                      Source https://stackoverflow.com/questions/67778134

                                                                                                      QUESTION

                                                                                                      C++, checking two txt files via fstream library to concatenate lines with the same ID
                                                                                                      Asked 2021-May-31 at 13:51

                                                                                                      I have to make a program which checks two txt files and concatenates the lines which start with the same ID. The results must be in a new file The files are in the following format:

                                                                                                      ID STRING_UP_TO_30_CHARS

                                                                                                      Error checking is not necessary but I have been stressing over this for quite a while now. I'm pretty new to programming in general as I am a freshman in University.

                                                                                                      Code that I have right now:

                                                                                                      int main()
                                                                                                      {
                                                                                                        temp();
                                                                                                      
                                                                                                        fstream file1;
                                                                                                        fstream file2;
                                                                                                        ofstream result;
                                                                                                      
                                                                                                        string line1, line2;
                                                                                                        int pos1, pos2;
                                                                                                        string id1, id2;
                                                                                                      
                                                                                                      
                                                                                                        file1.open("first.txt");
                                                                                                        file2.open("second.txt");
                                                                                                        result.open("resultat.txt");
                                                                                                      
                                                                                                        while(getline(file1, line1))
                                                                                                        {
                                                                                                          pos1 = line1.find(" "); //id and word are seperated by a space character, so I find the position of this space character
                                                                                                      
                                                                                                          id1 = line1;
                                                                                                          id1.erase(id1.begin()+pos1, id1.end()); //id is now a digit but string,
                                                                                                      
                                                                                                      
                                                                                                          while(getline(file2,line2))
                                                                                                          {
                                                                                                            pos2 = line2.find(" ");
                                                                                                      
                                                                                                            id2 = line2;
                                                                                                            id2.erase(id2.begin()+pos2, id2.end()); //id is digit now
                                                                                                            if(id2 == id1)
                                                                                                              {
                                                                                                                result<<<" "<<

                                                                                                      I made a function to make a temp file of the 2nd file since I tried deleting lines from the second document to make the code work. Simply ignore the temp() for now.

                                                                                                      The problem is that it only creates 2 lines in my result.txt file. I also have to add all the lines which are not paired with any lines from the other txt file as seperate lines in the final file but this is not a problem for me at the moment.

                                                                                                      Txt files I'm testing are probably important:

                                                                                                      21 para
                                                                                                      23 dyta
                                                                                                      27 treta
                                                                                                      11 katert
                                                                                                      12 pest
                                                                                                      13 fundit
                                                                                                      14 jojo
                                                                                                      41 vecant
                                                                                                      46 vecanti
                                                                                                      
                                                                                                      12 fifth
                                                                                                      21 first
                                                                                                      23 second
                                                                                                      29 third
                                                                                                      11 fourth
                                                                                                      13 last
                                                                                                      14 nono
                                                                                                      91 special
                                                                                                      104 specialty
                                                                                                      

                                                                                                      The result i get is:

                                                                                                      21 para 21 first
                                                                                                      23 dyta 23 second
                                                                                                      

                                                                                                      I have seen people suggesting vectors but I have not learned them at school and I am also not permitted to use any other libraries for my application.

                                                                                                      ANSWER

                                                                                                      Answered 2021-May-31 at 13:51
                                                                                                      while(getline(file2,line2))
                                                                                                      

                                                                                                      After this inner loop finds the line from the 2nd file that matches the 1st line in the first file, the outer loop runs again to read the 2nd line from the first file.

                                                                                                      However, afterwards, this inner loop simply continues reading from the 2nd file from the point where it stopped reading on the previous iteration of the outer loop. It found the first line, and the while loop terminated. Now, it again continues to getline from file2, so it simply continues reading the rest of it.

                                                                                                      The Golden Rule Of Computer Programming states: "a computer always does exactly what you tell it to do instead of what you want it to do". Its corollary states: "a computer never does what you never tell it to do".

                                                                                                      In this case you did not tell your computer to start at the beginning of the 2nd file, to begin searching it again for the line that matches the 2nd line from the first file. So, your computer never did that.

                                                                                                      Your C++ textbook should explain how to use seekg to seek the position where your fstream reads the file contents from. You simply need to explicitly seekg back to the beginning of file2 before the inner while loop, so that it always start reading from the very beginning of the 2nd file.

                                                                                                      Source https://stackoverflow.com/questions/67774932

                                                                                                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                                      Vulnerabilities

                                                                                                      No vulnerabilities reported

                                                                                                      Install pest

                                                                                                      You can download it from GitHub.
                                                                                                      PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.

                                                                                                      Support

                                                                                                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                                      Find more information at:
                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit
                                                                                                      CLONE
                                                                                                    • HTTPS

                                                                                                      https://github.com/pestphp/pest.git

                                                                                                    • CLI

                                                                                                      gh repo clone pestphp/pest

                                                                                                    • sshUrl

                                                                                                      git@github.com:pestphp/pest.git

                                                                                                    • Share this Page

                                                                                                      share link

                                                                                                      Explore Related Topics

                                                                                                      Consider Popular REST Libraries

                                                                                                      public-apis

                                                                                                      by public-apis

                                                                                                      json-server

                                                                                                      by typicode

                                                                                                      iptv

                                                                                                      by iptv-org

                                                                                                      fastapi

                                                                                                      by tiangolo

                                                                                                      beego

                                                                                                      by beego

                                                                                                      Try Top Libraries by pestphp

                                                                                                      pest-intellij

                                                                                                      by pestphpKotlin

                                                                                                      pest-plugin-laravel

                                                                                                      by pestphpPHP

                                                                                                      drift

                                                                                                      by pestphpPHP

                                                                                                      pest-plugin

                                                                                                      by pestphpPHP

                                                                                                      Compare REST Libraries with Highest Support

                                                                                                      fastapi

                                                                                                      by tiangolo

                                                                                                      dropwizard

                                                                                                      by dropwizard

                                                                                                      python

                                                                                                      by kubernetes-client

                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit