[R] A tibble with date column appears different in shiny

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Thu Mar 4 17:40:59 CET 2021


Hello,

This is a known issue with renderTable. Show the results with 
renderDataTable instead.

Hope this helps,

Rui Barradas

Às 15:24 de 03/03/21, Gayathri Nagarajan escreveu:
> Hi Team
> 
> I have a tibble like the below :
> 
> class(us_counties)
> [1] "tbl_df"     "tbl"        "data.frame"
> 
> head(us_counties)
> # A tibble: 6 x 8
>    date       deaths Todays_deaths county state fips
>    <date>      <dbl>         <dbl> <chr>  <chr> <chr>
> 1 2020-03-19      0             0 Abbev~ Sout~ 45001
> 2 2020-03-20      0             0 Abbev~ Sout~ 45001
> 3 2020-03-21      0             0 Abbev~ Sout~ 45001
> 4 2020-03-22      0             0 Abbev~ Sout~ 45001
> 5 2020-03-23      0             0 Abbev~ Sout~ 45001
> 6 2020-03-24      0             0 Abbev~ Sout~ 45001
> 
> str(us_counties)
> tibble [1,082,715 x 8] (S3: tbl_df/tbl/data.frame)
>   $ date         : Date[1:1082715], format: "2020-03-19" ...
>   $ deaths       : num [1:1082715] 0 0 0 0 0 0 0 0 0 0 ...
>   $ Todays_deaths: num [1:1082715] 0 0 0 0 0 0 0 0 0 0 ...
>   $ county       : chr [1:1082715] "Abbeville" "Abbeville" "Abbeville"
> "Abbeville" ...
>   $ state        : chr [1:1082715] "South Carolina" "South Carolina" "South
> Carolina" "South Carolina" ...
>   $ fips         : chr [1:1082715] "45001" "45001" "45001" "45001" ...
>   $ cases        : num [1:1082715] 1 1 1 1 1 1 3 4 4 4 ...
>   $ Todays_cases : num [1:1082715] 0 0 0 0 0 0 0 0 0 0 ...
>   - attr(*, "spec")=
>    .. cols(
>    ..   date = col_date(format = ""),
>    ..   county = col_character(),
>    ..   state = col_character(),
>    ..   fips = col_character(),
>    ..   cases = col_double(),
>    ..   deaths = col_double()
>    .. )
>   - attr(*, ".internal.selfref")=<externalptr>
>>
> 
> 
> 
> Now when I display this in shiny UI using a simple  command:
> 
> 
>     # Generate an HTML table view of the data ----
>     output$ttable <- renderTable({
>         head(us_counties
>              , n = input$obs)
>     })
> 
> 
> I get a display like the below
> 
> datedeathsTodays_deathscountystatefipscasesTodays_cases
> 18679.00 34.00 0.00 Abbeville South Carolina 45001 2184.00 0.00
> 18680.00 34.00 0.00 Abbeville South Carolina 45001 2191.00 0.00
> 18681.00 34.00 0.00 Abbeville South Carolina 45001 2192.00 0.00
> 
> This is the change I made
> 
> old code
> ========
>   #x <- getURL("
> https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv
> ")
>    #us_counties <- read.csv(text = x)
>    # 855612 Rows , 6 columns class(us_counties)
> 
> 
> this stopped working, so I changed to below
> 
> 
>    urlfile="
> https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv
> "
>    #GN added 3/3
>    us_counties<-read_csv(url(urlfile),col_types = list(date = col_date()))
> 
>   Please let me know how to correct this
> 
> Regards
> Gayathri
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list