Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final #27

Open
jmacost5 opened this issue Oct 5, 2019 · 113 comments
Open

Final #27

jmacost5 opened this issue Oct 5, 2019 · 113 comments

Comments

@jmacost5
Copy link

jmacost5 commented Oct 5, 2019

I was running the document to see what it looks like to get an idea of the tabs and it is giving me an error.
http://127.0.0.1:5011/final-project-dashboard-template.rmd

@lecy
Copy link
Collaborator

lecy commented Oct 6, 2019

That link does not work for me (it's local on your machine, not a public URL). What are the errors?

I just tried the template, and it works for me. I suspect you need to install the packages used in the document?

@jmacost5
Copy link
Author

jmacost5 commented Oct 6, 2019

Screen Shot 2019-10-06 at 12 54 20 PM
Screen Shot 2019-10-06 at 12 54 16 PM

@jmacost5
Copy link
Author

jmacost5 commented Oct 6, 2019

I did check to make sure all of the packages are loaded and they are.

@lecy
Copy link
Collaborator

lecy commented Oct 6, 2019

You might try creating a new folder in "My Documents" and name it anything ("dashboard"). Save the file there and try running.

R shiny creates a virtual server on your computer to host the shiny app, so it requires a few tools to play nicely with your local operating system.

I suspect it's a package issue, likely something with pandocs, htmltools, rmarkdown, knitr, or flexdashboard. Trying to diagnose now.

@sunaynagoel
Copy link

I am getting the same error as @jmacost5 even after making sure file is saved and all the packages are up to date. I even tried running code one line at a time, it does not give any error then.

@lecy
Copy link
Collaborator

lecy commented Oct 6, 2019

Can you both tell me your session info:

sessionInfo()

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.1

@jmacost5
Copy link
Author

jmacost5 commented Oct 6, 2019

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] rsconnect_0.8.15      knitr_1.24            DT_0.9                shiny_1.3.2          
 [5] viridis_0.5.1         viridisLite_0.3.0     leaflet_2.0.2         ggmap_3.0.0          
 [9] forcats_0.4.0         stringr_1.4.0         purrr_0.3.2           readr_1.3.1          
[13] tidyr_1.0.0           tibble_2.1.3          ggplot2_3.2.1         tidyverse_1.2.1      
[17] flexdashboard_0.5.1.1 pander_0.6.3          dplyr_0.8.3          

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2        lubridate_1.7.4   lattice_0.20-38   png_0.1-7        
 [5] assertthat_0.2.1  zeallot_0.1.0     digest_0.6.20     mime_0.7         
 [9] R6_2.4.0          cellranger_1.1.0  plyr_1.8.4        backports_1.1.4  
[13] evaluate_0.14     httr_1.4.1        pillar_1.4.2      RgoogleMaps_1.4.4
[17] rlang_0.4.0       lazyeval_0.2.2    readxl_1.3.1      rstudioapi_0.10  
[21] rmarkdown_1.15    htmlwidgets_1.3   munsell_0.5.0     broom_0.5.2      
[25] compiler_3.6.1    httpuv_1.5.2      modelr_0.1.5      xfun_0.9         
[29] pkgconfig_2.0.2   htmltools_0.3.6   tidyselect_0.2.5  gridExtra_2.3    
[33] crayon_1.3.4      withr_2.1.2       later_0.8.0       bitops_1.0-6     
[37] grid_3.6.1        nlme_3.1-140      jsonlite_1.6      xtable_1.8-4     
[41] gtable_0.3.0      lifecycle_0.1.0   magrittr_1.5      scales_1.0.0     
[45] cli_1.1.0         stringi_1.4.3     promises_1.0.1    xml2_1.2.2       
[49] generics_0.0.2    vctrs_0.2.0       rjson_0.2.20      tools_3.6.1      
[53] glue_1.3.1        hms_0.5.1         crosstalk_1.0.0   jpeg_0.1-8       
[57] yaml_2.2.0        colorspace_1.4-1  rvest_0.3.4       haven_2.1.1 

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

Ok, I think I have got it. If you are using the newest R version, 3.6.1, you need to re-install R shiny.

You can try the traditional version install.packages("shiny").

That did not work for me. I had to install the developer package from R Studio (which will be the most up-to-date code):

install.packages("devtools")
devtools::install_github("rstudio/shiny")

When you begin the install R will tell you that newer versions are available for a few packages, but they require compilation. It asks for your preference. I selected 1 for ALL. It took some time to update all of the code (because it compiles the packages directly on your machine), but that seemed to do the trick.

That should be the only step you need (it was the step that made a different on my machine after upgrading to R 3.6.1). I also updated knitr and rmarkdown along the way, so if the step above does not fix the issue then you can also try these:

install.packages('knitr', repos = c('https://xran.yihui.name', 'https://cran.r-project.org'))
devtools::install_github('rstudio/rmarkdown')

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

@sunaynagoel @jmacost5 Can you please try that step and update us on whether it fixed the issue?

@sunaynagoel
Copy link

@lecy I tried both the step mentioned above. It made no difference. Here is my sessionInfo() after running the steps.

 sessionInfo ()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 rstudioapi_0.10 knitr_1.25.1 magrittr_1.5
[5] flexdashboard_0.5.1.1 tidyselect_0.2.5 munsell_0.5.0 colorspace_1.4-1
[9] lattice_0.20-38 R6_2.4.0 rlang_0.4.0 plyr_1.8.4
[13] dplyr_0.8.3 tools_3.6.1 grid_3.6.1 gtable_0.3.0
[17] lemon_0.4.3 xfun_0.10 htmltools_0.4.0.9000 yaml_2.2.0
[21] digest_0.6.21 lazyeval_0.2.2 assertthat_0.2.1 tibble_2.1.3
[25] crayon_1.3.4 gridExtra_2.3 purrr_0.3.2 ggplot2_3.2.1
[29] rsconnect_0.8.15 evaluate_0.14 glue_1.3.1 rmarkdown_1.16
[33] compiler_3.6.1 pillar_1.4.2 scales_1.0.0 jsonlite_1.6
[37] pkgconfig_2.0.3

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

If you open base R (not R Studio) and select packages --> update packages then select a mirror, which packages are listed? 

@sunaynagoel
Copy link

My Base R does not give me an option of select packages. It has the following screen. But when I go in packages list somehow Shiny does not show as loaded even though I installed it.
Screen Shot 2019-10-06 at 6 13 20 PM

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

Try in R Studio then under Tools --> Check for package update.

If shiny will not load with library(shiny) it means the re-install failed. That is likely the culprit.

@jmacost5
Copy link
Author

jmacost5 commented Oct 7, 2019

So I need to put these packages in my base R and not my R studio.

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

@jmacost5 they are all the same packages, it's just easier to install them in base R sometimes because R Studio will automatically load some packages it needs, thus making it harder to update them.

Once they have installed in the basic R console they will be available in R Studio as well.

@sunaynagoel
Copy link

@lecy I tried a few things

  1. R Studio, under Tools --> Shows all my packages are up-to date.
  2. library(shiny) does not give any errors.
  3. Loaded the package in Base R as well. Restarted everything.

When I run the my .rmd file it does not give any errors, but it generates a file which opens up in new window (which is what it is supposed to do). Instead of showing widgets it shows only HTML type of codes in red.

I am not sure what am I doing wrong?

@jmacost5
Copy link
Author

jmacost5 commented Oct 7, 2019

I do not think it worked because I am still getting the same message.R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rsconnect_0.8.15 pander_0.6.3 DT_0.9 shiny_1.3.2.9001
[5] viridis_0.5.1 viridisLite_0.3.0 leaflet_2.0.2 ggmap_3.0.0
[9] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3 purrr_0.3.2
[13] readr_1.3.1 tidyr_1.0.0 tibble_2.1.3 ggplot2_3.2.1
[17] tidyverse_1.2.1 flexdashboard_0.5.1.1

loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 lubridate_1.7.4 lattice_0.20-38 png_0.1-7
[5] assertthat_0.2.1 zeallot_0.1.0 digest_0.6.21 mime_0.7
[9] R6_2.4.0 cellranger_1.1.0 plyr_1.8.4 backports_1.1.4
[13] evaluate_0.14 httr_1.4.1 pillar_1.4.2 RgoogleMaps_1.4.4
[17] rlang_0.4.0 lazyeval_0.2.2 readxl_1.3.1 rstudioapi_0.10
[21] rmarkdown_1.16.1 htmlwidgets_1.3 munsell_0.5.0 broom_0.5.2
[25] compiler_3.6.1 httpuv_1.5.2.9000 modelr_0.1.5 xfun_0.10
[29] pkgconfig_2.0.2 htmltools_0.4.0.9000 tidyselect_0.2.5 gridExtra_2.3
[33] crayon_1.3.4 withr_2.1.2 later_1.0.0 bitops_1.0-6
[37] grid_3.6.1 nlme_3.1-140 jsonlite_1.6 xtable_1.8-4
[41] gtable_0.3.0 lifecycle_0.1.0 magrittr_1.5 scales_1.0.0
[45] cli_1.1.0 stringi_1.4.3 promises_1.1.0 xml2_1.2.2
[49] generics_0.0.2 vctrs_0.2.0 rjson_0.2.20 tools_3.6.1
[53] glue_1.3.1 hms_0.5.1 crosstalk_1.0.0 jpeg_0.1-8
[57] fastmap_1.0.0 yaml_2.2.0 colorspace_1.4-1 rvest_0.3.4
[61] knitr_1.25.1 haven_2.1.1

@sunaynagoel
Copy link

sunaynagoel commented Oct 7, 2019

@jmacost5 I am on the same boat as well. It did not work for me either. I hope we can figure it out sooner and then later so we can work on actual Lab. Good luck.
@lecy do you think shiny and rconnect don't interact well each other. I do get this message in my base R
Attaching package: ‘rsconnect’

The following object is masked from ‘package:shiny’:

serverInfo

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

@jmacost5 do you also have a Mac?

It should not be a conflict with shiny and rsconnect, though you can comment out packages to see if it works then.

Can you also re-install leaflet? The package conflict I had was leaflet and shiny.

We might have to schedule a Zoom call tomorrow to diagnose.

@jmacost5
Copy link
Author

jmacost5 commented Oct 7, 2019

ok, I will reinstall the package. Also I do have a Mac and if office hours are still the same I can meet at that time tomorrow. I am also getting an error when I re booted R studio that I did not get before.
Error in value[3L] :
Package ‘knitr’ version 1.25 cannot be unloaded:
Error in unloadNamespace(package) : namespace ‘knitr’ is imported by ‘rmarkdown’ so cannot be unloaded

@jrcook15
Copy link

jrcook15 commented Oct 7, 2019

Hi Professor Lecy, can you please activate the link to submit the final assignment? Only the Code Through Tutorial is showing on Canvas. Thank you.

@sunaynagoel
Copy link

@lecy - I pointed out 3 problems so far, when I run the document

  1. install.packages("rconnect")
    Warning in install.packages :
    package ‘rconnect’ is not available (for R version 3.6.1)

  2. library( pander )

Attaching package: ‘pander’

The following object is masked from ‘package:shiny’:

p
  1. library( DT )

Attaching package: ‘DT’

The following objects are masked from ‘package:shiny’:

dataTableOutput, renderDataTable

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

@jrcook15 the link should be working now

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

@sunaynagoel masking is not be a problem. That just means that two packages have a function of the same name, so one has been set as the default when they are called.

The other package is called "rsconnect" not "rconnect". See if install.packages("rsconnect") works.

@castower
Copy link

castower commented Oct 7, 2019

Hello all,
I have also gotten the same errors. I first ran this code:

install.packages("devtools")
devtools::install_github("rstudio/shiny")

in RStudio, but it didn't make any changes.

I am now trying to install in base R, but I'm getting the following error:

devtools::install_github("rstudio/shiny")
Skipping install of 'shiny' from a github remote, the SHA1 (89bd7e90) has not changed since last install.
  Use `force = TRUE` to force installation

I am not sure how to proceed.

Thanks!
Courtney

@castower
Copy link

castower commented Oct 7, 2019

Here's my systemInfo():

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 
 
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2        ps_1.3.0          prettyunits_1.0.2 rprojroot_1.3-2   withr_2.1.2       digest_0.6.21    
 [7] crayon_1.3.4      assertthat_0.2.1  R6_2.4.0          backports_1.1.4   magrittr_1.5      rlang_0.4.0      
[13] cli_1.1.0         curl_4.0          fs_1.3.1          remotes_2.1.0     testthat_2.2.1    callr_3.3.2      
[19] ellipsis_0.3.0    desc_1.2.0        devtools_2.2.1    tools_3.6.1       glue_1.3.1        pkgload_1.0.2    
[25] compiler_3.6.1    processx_3.4.1    pkgbuild_1.0.5    sessioninfo_1.1.1 memoise_1.1.0     usethis_1.5.1    

@lecy
Copy link
Collaborator

lecy commented Oct 7, 2019

Thanks to @sunaynagoel for helping me find this issue. I had downloaded the data dictionary from Tempe's open data site, and they managed to embed some special characters in their Excel file. Can you find it?

INCAPACITATING INJURY - Any   
                         injury, other than a fatal   
                         injury, which prevents the   
                        injured person from walking,  
                       driving or normally continuing 
                       the activities the person was  
                        capable of performing before  
                         the injury occurred. Often   
                        defined as needing help from  
                        the scene.� Includes: severe  
                           lacerations, broken or     
                         distorted limbs, skull or    
                         chest injuries, abdominal    
                       injuries, unconsciousness when 
                        taken from the crash scene.  

So that was breaking the HTML code for some people and not others. It's an easy fix, just replace the embedded data dictionary chunks with this one chunk that reads in a clean version of the data dictionary:

URL.dd <- "https://raw.githubusercontent.com/DS4PS/cpp-526-fall-2019/master/labs/final-project/TempeTrafficAccidentsDataDictionary.csv"
data.dictionary <- read.csv( URL.dd, stringsAsFactors=F )
data.dictionary %>%
  select( column, description ) %>%
  pander( )

I've updated the template.

Let me know if you are having other issues getting the template to work!

@castower
Copy link

castower commented Oct 7, 2019

@lecy I re-downloaded the template, but it still had the old url.

I tried to just replace the data in the code, but I'm getting this error:

Error: object 'dat' not found

I tried to run the following code with dat instead of data.dictionary:

URL.dd <- "https://raw.githubusercontent.com/DS4PS/cpp-526-fall-2019/master/labs/final-project/TempeTrafficAccidentsDataDictionary.csv"
dat <- read.csv( URL.dd, stringsAsFactors=F )
dat %>%
  select( column, description ) %>%
  pander( )

and I got this error:

Error: replacement has 0 rows, data has 32

@castower
Copy link

castower commented Oct 7, 2019

I re-downloaded the template again and this time it worked! I'm still curious how I would've gotten the CSV file to work though, if you have any suggestions. Thanks!

@castower
Copy link

renderPrint({

Chart3 <- dat %>%
  filter( age.cat, as.numeric(hour) >= 0, day %in% input$days3, Gender_Drv1 %in% input$d1gender2, Unittype_One %in% input$d1pedcy2) %>%
  group_by( age.cat, hour ) %>%
  summarize( harm = sum(Totalinjuries) + sum(Totalfatalities) ) %>%
  select( hour, harm, age.cat )

dput( Chart3 )

})

The only output I'm getting is <shiny.render.function>

@jmacost5
Copy link
Author

For some reason d2 is not being found when I run my program completely

@castower
Copy link

Hello all,
I've almost got my dashboard done, but one problem that I have discovered is that when the bar charts I created do not have a value, instead of just presenting a blank graph, it gives the following error:

Error: Aesthetics must be either length 1 or the same as the data (1): y

I've currently made a sidebar note to indicate that this simply means there's no data, but I'm curious if there is a way to stop this error.

Here is my code:

Input:

selectInput("collision", label = h3("Type of Collision"), 
    choices = list("ANGLE (Front To Side)(Other Than Left Turn)",
                   "Head On",
                   "Left Turn",
                   "Other",
                   "Rear End",
                   "Sideswipe Same Direction",
                   "Single Vehicle",
                   "Unknown" ),
    selected = c("Rear End"))
selectInput("gen", label = h3("Gender"), 
    choices = c("Male",
                "Female", 
                "Unknown"), 
    selected = c("Male"))
radioButtons("weather", label = h3("Weather"),
    choices = c("Dust Storm" = "Blowing Sand Soil Dirt", 
                "Clear", 
                "Cloudy",
                "Rain",
                "Unknown"), 
    selected = c("Clear"))

Output:

 renderPlot( {

   
Chart4 <- dat %>% filter( age.cat== "Youth", Gender_Drv1 %in% input$gen, Weather %in% input$weather, Collisionmanner %in% input$collision) %>%
  group_by( age.cat ) %>%
  summarize( harm = sum(Totalinjuries) + sum(Totalfatalities) )

ggplot(data=Chart4, aes(x=input$collision, y=Chart4$harm)) +
  geom_bar(stat="identity", fill="firebrick") + labs(x="Collision Type", y = "Number of Harmful Crashes") + theme_minimal()

})
   

For example, if I select dust storm and female, my Youth and Senior categories produce the error message above.

@RickyDuran
Copy link

When I try to publish, I am getting this request, although when trying to do it with something else I didn't get this, and created an app in shiny.

image

@jmacost5
Copy link
Author

I am doing just the alcohol consumption. Does this make sense for out code?

Drivers 2 {data-orientation=rows}

Sidebar {.sidebar}

Driver Characteristics

sliderInput("driver.1.age", label = h4("Driver 1 Age"), 
            min = 15, max = 100, value = c(18,36) )
sliderInput("driver.2.age", label = h4("Driver 2 Age"), 
            min = 15, max = 100, value = c(18,36) )
selectInput("driver.1.gender", label = h4("Driver 1 Gender"), 
    choices = c("Male","Female", "Unknown"), selected = c("Male"))
selectInput("driver.2.gender", label = h4("Driver 2 Gender"), 
    choices = c("Male","Female", "Unknown"), selected = c("Male"))
radioButtons("AlcoholUse_Drv1", label = h4("Driver 1 Influence"),
    choices = c("No Apparent Influence", "Alcohol"), selected = c("No Apparent Influence"))
radioButtons("AlcoholUse_Drv2", label = h4("Driver 2 Influence"),
    choices = c("No Apparent Influence", "Alcohol"), selected = c("No Apparent Influence"))

Row

Number of Crashes

renderValueBox({
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
            Unittype_One %in% input$d1pedcy, 
            Unittype_Two %in% input$d2pedcy)
  
  crashes <- count( d2 )
  valueBox(crashes, 
           icon = "fa-pencil",
           color = ifelse( crashes > 50, "danger", "primary") )
})

Total Injuries

renderValueBox({
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
            Unittype_One %in% input$d1pedcy, 
            Unittype_Two %in% input$d2pedcy )
  
  total.injuries <- sum( d2$Totalinjuries )
  valueBox(total.injuries, 
           icon = "fa-angry",
           color = ifelse( total.injuries > 30, "danger", "primary" ))
})

Total Fatalities

renderValueBox({
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
            Unittype_One %in% input$d1pedcy, 
            Unittype_Two %in% input$d2pedcy )

  total.fatalities <- sum( d2$Totalfatalities )
  valueBox( total.fatalities, 
            icon = "fa-briefcase-medical",
            color = ifelse(total.fatalities > 10, "danger", "primary"))
})

Rate of Harm

renderValueBox({
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
            Unittype_One %in% input$d1pedcy, 
            Unittype_Two %in% input$d2pedcy )
  
  rate.of.harm <- round(length(which(d2$harm == "Harm"))/count(d2), 3)
  valueBox(rate.of.harm, 
           icon = "fa-pencil",
           color = ifelse(rate.of.harm > 0.5, "danger", "primary"))
})

Column

Driver 1


renderLeaflet({
  
  # days.of.week <- input$days    # vector will all checked values
  # start.time <- input$hour[1]   # sliderInput lower value
  # end.time  <-  input$hour[2] 
  
  d10 <-
    dat %>%
    filter( Age_Drv1 >= input$driver.1.age[1] & Age_Drv1 <= input$driver.1.age[2], 
            Gender_Drv1 %in% input$driver.1.gender, 
            AlcoholUse_Drv1 %in% input$driver.1.AlcoholUse)
  
  d10$col.vec <- ifelse( d10$nohurt, "gray20", ifelse(d10$inj, "steelblue", "darkorange") )              
    
  point.size <- d10$Totalinjuries + d10$Totalfatalities

  crash.details <- paste0( "Time: ", d10$DateTime, "<br>",
                     "Total Fatalities: ", d10$Totalfatalities, "<br>",
                     "Total Injuries: ", d10$Totalinjuries, "<br>",
                     "Collision type: ", d10$Collisionmanner)
  
  tempe <- leaflet( ) %>% 
              addProviderTiles( "CartoDB.Positron" )  %>%
              setView( lng=-111.9278, lat=33.39951, zoom=13 )
  
  
  addCircles( tempe, lng=d10$Longitude, lat=d10$Latitude,
              fillColor=d10$col.vec, fillOpacity=0.5, 
              stroke=F, radius=50*(1+0.33*point.size),
              popup=crash.details )


})

Driver 2


renderLeaflet({
  
  # days.of.week <- input$days    # vector will all checked values
  # start.time <- input$hour[1]   # sliderInput lower value
  # end.time  <-  input$hour[2] 
  
  d11 <-
    dat %>%
    filter( Age_Drv2 >= input$driver.2.age[1] & Age_Drv2 <= input$driver.2.age[2], 
            Gender_Drv2 %in% input$driver.2.gender, 
             AlcoholUse_Drv2 %in% input$driver.2.AlcoholUse )
  
  d11$col.vec <- ifelse( d11$nohurt, "gray20", ifelse(d11$inj, "steelblue", "darkorange") )              
    
  point.size2 <- d11$Totalinjuries + d11$Totalfatalities

  crash.details2 <- paste0( "Time: ", d11$DateTime, "<br>",
                     "Total Fatalities: ", d11$Totalfatalities, "<br>",
                     "Total Injuries: ", d11$Totalinjuries, "<br>",
                     "Collision type: ", d11$Collisionmanner)
  
  tempe2 <- leaflet( ) %>% 
              addProviderTiles( "CartoDB.Positron" )  %>%
              setView( lng=-111.9278, lat=33.39951, zoom=13 )
  
  
  addCircles( tempe2, lng=d11$Longitude, lat=d11$Latitude,
              fillColor=d11$col.vec, fillOpacity=0.5, 
              stroke=F, radius=50*(1+0.33*point.size2),
              popup=crash.details2 )


})

@lecy
Copy link
Collaborator

lecy commented Oct 10, 2019

@RickyDuran Are you trying to publish through shinyapp.io or through R Studio Connect? Connect is a different service that we currently don't have configured. I would need to know more about what steps you followed to get that window to diagnose.

@RickyDuran
Copy link

@lecy, after reading through some of the thread that was hidden, I noticed you had said to redownload the template. I did so, and it seems to have fixed the issue.

@lecy
Copy link
Collaborator

lecy commented Oct 10, 2019

@castower It would require conditional statements (control structures in computer speak) that we have not learned yet.

I can send some code if you want to try it out.

if( condition is met)
{  do the thing }
if( condition is not met )
{ print something else }

@lecy
Copy link
Collaborator

lecy commented Oct 10, 2019

@jmacost5

Does this make sense for out code?

Can you be more specific? Do you want feedback on the design or on something not working? What are you trying to show with that tab?

@castower
Copy link

@castower It would require conditional statements (control structures in computer speak) that we have not learned yet.

I can send some code if you want to try it out.

if( condition is met)
{  do the thing }
if( condition is not met )
{ print something else }

@lecy That would be great. If it helps, basically what I'm trying to accomplish is:

If there's one more crashes then the chart displays.

If not, then there's a blank chart OR maybe a message that says 'No data available' instead of the odd error message that would be hard for someone unfamiliar with R to understand.

I can re-send my .rmd file if needed.

Thanks!

@RickyDuran
Copy link

When trying to deploy the app, I get the message: ERROR: An error has occurred. Check your logs or contact the app author for clarification. It is showing up in the viewer, in R, but not in Shinyapps.

@jmacost5
Copy link
Author

jmacost5 commented Oct 10, 2019

I am getting an error when I put it into the shinny document. I just do not understand how to make it better

image

Here is the code I have currently:Driver Characteristics {data-orientation=rows}

Sidebar {.sidebar}

Driver Characteristics

sliderInput("driver.1.age", label = h4("Driver 1 Age"), 
            min = 15, max = 100, value = c(18,36) )
sliderInput("driver.2.age", label = h4("Driver 2 Age"), 
            min = 15, max = 100, value = c(18,36) )
selectInput("driver.1.gender", label = h4("Driver 1 Gender"), 
    choices = c("Male","Female", "Unknown"), selected = c("Male"))
selectInput("driver.2.gender", label = h4("Driver 2 Gender"), 
    choices = c("Male","Female", "Unknown"), selected = c("Male"))
radioButtons("AlcoholUse_Drv1", label = h4("Driver 1 Influence"),
    choices = c("No Apparent Influence", "Alcohol"), selected = c("No Apparent Influence"))
radioButtons("AlcoholUse_Drv2", label = h4("Driver 2 Influence"),
    choices = c("No Apparent Influence", "Alcohol"), selected = c("No Apparent Influence"))

Row

Number of Crashes

renderValueBox({
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
            AlcoholUse_Drv1 %in% input$driver.1.AlcoholUse,
            AlcoholUse_Drv2 %in% input$driver.2.AlcoholUse )
  
  crashes <- count( d2 )
  valueBox(crashes, 
           icon = "fa-pencil",
           color = ifelse( crashes > 50, "danger", "primary") )
})

Total Injuries

renderValueBox({
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
           AlcoholUse_Drv1 %in% input$driver.1.AlcoholUse,
            AlcoholUse_Drv2 %in% input$driver.2.AlcoholUse  )
  
  total.injuries <- sum( d2$Totalinjuries )
  valueBox(total.injuries, 
           icon = "fa-angry",
           color = ifelse( total.injuries > 30, "danger", "primary" ))
})

Total Fatalities

renderValueBox({
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
            AlcoholUse_Drv1 %in% input$driver.1.AlcoholUse,
            AlcoholUse_Drv2 %in% input$driver.2.AlcoholUse  )

  total.fatalities <- sum( d2$Totalfatalities )
  valueBox( total.fatalities, 
            icon = "fa-briefcase-medical",
            color = ifelse(total.fatalities > 10, "danger", "primary"))
})

Rate of Harm

renderValueBox({
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
            AlcoholUse_Drv1 %in% input$driver.1.AlcoholUse,
            AlcoholUse_Drv2 %in% input$driver.2.AlcoholUse  )
  
  rate.of.harm <- round(length(which(d2$harm == "Harm"))/count(d2), 3)
  valueBox(rate.of.harm, 
           icon = "fa-pencil",
           color = ifelse(rate.of.harm > 0.5, "danger", "primary"))
})

Outputs

Traffic Accidents by Driver Characteristics


renderLeaflet({
  
  # days.of.week <- input$days    # vector will all checked values
  # start.time <- input$hour[1]   # sliderInput lower value
  # end.time  <-  input$hour[2] 
  
  d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
            Age_Drv2 >= input$d2age[1] & Age_Drv2 <= input$d2age[2], 
            Gender_Drv1 %in% input$d1gender, 
            Gender_Drv2 %in% input$d2gender, 
            AlcoholUse_Drv1 %in% input$driver.1.AlcoholUse,
           AlcoholUse_Drv2 %in% input$driver.2.AlcoholUse )
  
  
  
  d2$col.vec <- ifelse( d2$nohurt, "gray20", ifelse(d2$inj, "steelblue", "darkorange") )              
    
  point.size <- d2$Totalinjuries + d2$Totalfatalities

  crash.details <- paste0( "Time: ", d2$DateTime, "<br>",
                     "Total Fatalities: ", d2$Totalfatalities, "<br>",
                     "Total Injuries: ", d2$Totalinjuries, "<br>",
                     "Collision type: ", d2$Collisionmanner)
  
  tempe <- leaflet( ) %>% 
              addProviderTiles( "CartoDB.Positron" )  %>%
              setView( lng=-111.9278, lat=33.39951, zoom=13 )
  
  
  addCircles( tempe, lng=d2$Longitude, lat=d2$Latitude,
              fillColor=d2$col.vec, fillOpacity=0.5, 
              stroke=F, radius=50*(1+0.33*point.size),
              popup=crash.details )


})

@etbartell
Copy link

I am attempting to make a plot showing different degrees of injury severity over time. The sidebar with the inputs is working but the output area is blank. I think it's because the date is a character variable that can be graphed but I'm not sure. I tired converting it to numeric but it just made everything "NA". Here is my input:

dat$MDY <- format( date.vec, format="%D" )
selectInput( "injuries", label = strong("Traffic Acciddent Injury Trends"), choices = c( "No Injury", "Possible Injury", "Non Incapacitating Injury", "Incapacitating Injury", "Fatal" ), selected = "No Injury")

dateRangeInput("date_range", label = h3("Date Range"), start = "01/01/2017", end = "12/31/2017", min = "01/012012", max = "12/31/2017", format = "mm/dd/yyyy", startview = "month", language = "en", separator = " to ")

and the current draft of my output:

renderPlot({
  
  d4 <-
    dat %>%
    filter( Injuryseverity %in% input$injuries, MDY >= input$date_range[1] & MDY < input$date[2] ) %>%
    count( MDY, Injuryseverity ) %>%
    group_by( MDY ) %>%
    mutate( total.injury = n )
  plot.new()
  plot.window(xlim = c(input$date[1], input$date[2]), ylim = c(0,10))
  points( d4$MDY, d4$total.injury, col = "dodgerblue4", pch=19, type = "l", cex = 2)
  xlab="Date"
  ylab="Injury Count"
  main="Tempe Accident Injury Trends"
})

@meliapetersen
Copy link

Hi, I am having an issue with my dropdown widgets connecting to the map. I am able to select the different options, but the crashes are not showing up on the leaflet. Here is my code:

`
Traffic Accidents By Substance Abuse

Inputs {.sidebar}


selectInput("d1.substance", label = h4("Driver 1 Substance Use"), 
    choices = c("Alcohol", "Drugs", "No Apparent Use", "Unknown"), selected = c("No Apparent Use"))
selectInput("d2.substance", label = h4("Driver 2 Substance Use"), 
    choices = c("Alcohol", "Drugs", "No Apparent Use", "Unknown"), selected = c("No Apparent Use"))

# parameters

Outputs

Traffic Accidents By Substance Abuse


#leaflet
renderLeaflet({
  
  # days.of.week <- input$days    # vector will all checked values
  # start.time <- input$hour[1]   # sliderInput lower value
  # end.time  <-  input$hour[2] 
  
  d2 <-
    dat %>%
    filter( d1.substance %in% input$d1.substance, 
            d2.substance %in% input$d2.substance, 
             )
  
  d2$col.vec <- ifelse( d2$nohurt, "gray20", ifelse(d2$inj, "steelblue", "darkorange") )              
    
  point.size <- d2$Totalinjuries + d2$Totalfatalities

  crash.details <- paste0( "Time: ", d2$DateTime, "<br>",
                     "Total Fatalities: ", d2$Totalfatalities, "<br>",
                     "Total Injuries: ", d2$Totalinjuries, "<br>",
                     "Collision type: ", d2$Collisionmanner)
  
  tempe <- leaflet( ) %>% 
              addProviderTiles( "CartoDB.Positron" )  %>%
              setView( lng=-111.9278, lat=33.39951, zoom=13 )
  
  
  addCircles( tempe, lng=d2$Longitude, lat=d2$Latitude,
              fillColor=d2$col.vec, fillOpacity=0.5, 
              stroke=F, radius=50*(1+0.33*point.size),
              popup=crash.details )


})
```   `

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@jmacost5 It is the same issue you were having before: #27 (comment)

You name your widget driver.1.age:

sliderInput("driver.1.age", label = h4("Driver 1 Age"), 
            min = 15, max = 100, value = c(18,36) )

But then in the renderValueBoxes section you are referencing a widget named d1age.

 d2 <-
    dat %>%
    filter( Age_Drv1 >= input$d1age[1] & Age_Drv1 <= input$d1age[2], 
    ... 

You will always reference the user input at input$widget_name where widget_name is whatever name you give it. If you use different names the render function will not be able to find the user inputs.

Should be:

sliderInput( "driver.1.age", label = h4("Driver 1 Age"), 
            min = 15, max = 100, value = c(18,36)  )
 d2 <-
    dat %>%
    filter( Age_Drv1 >= input$driver.1.age[1] & Age_Drv1 <= input$driver.1.age[2], 
    ... 

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@etbartell You are missing a date separator here in the min argument:

dateRangeInput( "date_range", label = h3("Date Range"), 
    start = "01/01/2017", end = "12/31/2017", 
    min = "01/012012", max = "12/31/2017", 
    format = "mm/dd/yyyy", startview = "month", language = "en", separator = " to ")

You might double-check the variable type returned by the date widget. I suspect it is a character vector, and you might have to convert it to a date object before using in a date comparison.

https://shiny.rstudio.com/gallery/widget-gallery.html

It can be tricky because a date compared to text will still evaluate, it just casts both as text:

widget.dates <- c("01/01/2017","12/31/2017")
widget.dates.1 <- strptime( widget.dates, format="%m/%d/%Y" )
class( widget.dates.1 )
widget.dates.2 <- format( widget.dates.1, format="%D" )
class( widget.dates.2 )

widget.dates.1
[1] "2017-01-01 MST" "2017-12-31 MST"
widget.dates.1 > "06/01/2017" # comparison to text
[1] TRUE TRUE
widget.dates.1 >  strptime( "06/01/2017", format="%m/%d/%Y" )# comparison to date
[1] FALSE  TRUE

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@meliapetersen I am not sure if this is the problem, but you have an extra comma in your filter statement:

  d2 <-
    dat %>%
    filter( d1.substance %in% input$d1.substance, 
            d2.substance %in% input$d2.substance, 
             )

Should be:

  d2 <-
    dat %>%
    filter( d1.substance %in% input$d1.substance, 
            d2.substance %in% input$d2.substance  )

@meliapetersen
Copy link

meliapetersen commented Oct 11, 2019

@meliapetersen I am not sure if this is the problem, but you have an extra comma in your filter statement:

  d2 <-
    dat %>%
    filter( d1.substance %in% input$d1.substance, 
            d2.substance %in% input$d2.substance, 
             )

Should be:

  d2 <-
    dat %>%
    filter( d1.substance %in% input$d1.substance, 
            d2.substance %in% input$d2.substance  )

@lecy I took out the comma and it still isn't running the data to the widget.

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@meliapetersen Do any of your widgets on separate tabs have identical names?

@meliapetersen
Copy link

@lecy No, I don't think so. I renamed the two widgets "Driver 1 Substance Use" and "Driver 2 Substance Use". Is that what you're referring to?

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@meliapetersen I meant the inputId:

selectInput( inputId="d1.substance", 
    label = h4("Driver 1 Substance Use"), 
    choices = c("Alcohol", "Drugs", 
                     "No Apparent Use", "Unknown"), 
    selected = c("No Apparent Use"))

@meliapetersen
Copy link

@lecy No, this is the first time that I've used d1.substance and d2.substance in a widget. This is the first tab that I am working on and the only place that I mention it outside of its naming in the mutate function at the top of the doc (line 61 of the template).

@etbartell
Copy link

I figured it had something to do with the class of the variable, but was unsure how to change it to something that could be read numerically. Here is my altered output code:

renderPlot({
  d4 <-
    dat %>%
    MDY <- strptime( dat$DateTime, format="%m/%d/%Y" ) %>%
    filter( Injuryseverity %in% input$injuries, MDY >= input$date_range[1] & MDY <= input$date_range[2] ) %>%
    count( MDY, Injuryseverity ) %>%
    group_by( MDY ) %>%
    mutate( total.injury = n)
  
plot.new()
  points( d4$MDY, d4$total.injury, col = "dodgerblue4", pch=19, type = "l", cex = 2)
  xlab="Date"
  ylab="Injury Count"
  main="Tempe Accident Injury Trends"
})

It's now giving me the error message: "no applicable method for 'filter_' applied to an object of class "c('POSIXlt', 'POSIXt')""

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@meliapetersen I don't see something obvious. Can you send me your RMD by email?

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@etbartell You mangled your data recipe. You have an assignment operator in the middle, and you are use $ references. Try something like:

  d4 <-
    dat %>%
    mutate( MDY = strptime( DateTime, format="%m/%d/%Y" ) ) %>%
    filter( Injuryseverity %in% input$injuries, 
            MDY >= input$date_range[1] & MDY <= input$date_range[2]  ) %>%
    count( MDY, Injuryseverity ) %>%
    group_by( MDY ) %>%
    mutate( total.injury = n)

But your main problem is you are still comparing MDY (a date object) to input$date_range (a character vector). So before your data recipe try something like:

date.range <- strptime( input$date_range, format="%X/%X/%X" )  # not sure the format here

Then your filter comparisons would be:

MDY >= date.range[1] 

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@etbartell OK, looking back at how you created the dates. Note the difference between MDY and input$date_range formats:

"01/01/2017"  # widget dates
"01/01/17"      # MDY after format( date.vec, "%D" )

And the appropriate time conversion functions for each (upper versus lower-case Y):

strptime( "01/01/2017", format="%m/%d/%Y" )
strptime( "01/01/17", format="%m/%d/%y" )

@etbartell
Copy link

Yeah I changed the date format and It's still telling me it's the wrong class:

renderPlot({
  date.range <- strptime( input$date_range, format="%m/%d/%Y")
  d4 <-
    dat %>%
    mutate( MDY = strptime( dat$DateTime, format="%m/%d/%Y" ) )%>%
    filter( Injuryseverity %in% input$injuries, MDY >= date.range[1] & MDY <= date.range[2] ) %>%
    count( MDY, Injuryseverity ) %>%
    group_by( MDY ) %>%
    mutate( total.injury = n)
  
plot.new()
  points( d4$MDY, d4$total.injury, col = "dodgerblue4", pch=19, type = "l", cex = 2)
  xlab="Date"
  ylab="Injury Count"
  main="Tempe Accident Injury Trends"
})

"Column MDY is of unsupported class POSIXlt; please use POSIXct instead"

Then when I tried putting "as.POSIXct()" before the dates it just returned a blank page. I don't get why it's not working on mine when I'm using the same steps from the tutorials.

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@etbartell I think this might work (change Y to y in MDY reformat and take the dat$ out of the first mutate):

  date.range <- strptime( input$date_range, format="%m/%d/%Y")
  d4 <-
    dat %>%
    mutate( MDY = strptime( DateTime, format="%m/%d/%y" ) )%>%
    filter( Injuryseverity %in% input$injuries, 
           MDY >= date.range[1] & MDY <= date.range[2] ) %>%
    count( MDY, Injuryseverity ) %>%
    group_by( MDY ) %>%
    mutate( total.injury = n)

@lecy
Copy link
Collaborator

lecy commented Oct 11, 2019

@etbartell One more potential issue - should your last mutate() be?

  date.range <- strptime( input$date_range, format="%m/%d/%Y")
  d4 <-
    dat %>%
    ...
    mutate( total.injury = sum(n) )

d4$MDY here is not numeric. Does that work in a plot function? Should points be plot()?

plot( d4$MDY, d4$total.injury, 
  col = "dodgerblue4", pch=19, type = "l", cex = 2,
  xlab="Date",
  ylab="Injury Count",
  main="Tempe Accident Injury Trends" )

If you started with this variable, it might be easier to plot since it's numbers 1 to 365. Otherwise you could convert m4$MDY to this format before plotting?

dat$day365 <- format( date.vec, format="%j" )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants