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

Sum of value showing NaN in summarywidget #486

Open
lyamlim97 opened this issue Mar 26, 2024 · 2 comments
Open

Sum of value showing NaN in summarywidget #486

lyamlim97 opened this issue Mar 26, 2024 · 2 comments

Comments

@lyamlim97
Copy link

lyamlim97 commented Mar 26, 2024

Using a crosstalk::SharedData dataframe, the result after calling

r htmlWidget = htmlwidgets::createWidget( name = 'summarywidget', x, width = width, height = height, package = 'summarywidget', elementId = elementId, dependencies = crosstalk::crosstalkLibs() ), the generated HTML shows NaN.

CC: @Thepan97

@gadenbuie
Copy link
Collaborator

Can you please provide a minimal reprex (reproducible example)? The goal of a reprex is to make it as easy as possible for us to recreate your problem so that we can fix it: please help us help you! If you've never heard of a reprex before, start by reading about the reprex package or the guidance from the Shiny team on creating a reproducible example.

@lyamlim97
Copy link
Author

sharedData <- function(df) {
  SharedData$new(df)
}

df <- read.csv("sample.csv")

df_shared <- sharedData(df)

key <- df_shared$key()
group <- df_shared$groupName()
data <- df_shared$origData()


selection = ~favourableTop10 == "Unfavourable Top 10"
selection = eval(selection[[2]], data, environment(selection))

data = data[selection, ]
key = key[selection]

column = 'Revenue'
data = data[[column]]

statistic <- 'sum'

digits = 2

x = list(
  data = data,
  settings = list(
    statistic = statistic,
    digits = digits,
    crosstalk_key = key,
    crosstalk_group = group
  )
)

width = NULL
height = NULL
elementId = NULL

htmlwidgets::createWidget(
  name = 'summarywidget',
  x,
  width = width,
  height = height,
  package = 'summarywidget',
  elementId = elementId,
  dependencies = crosstalk::crosstalkLibs()
)

Above code uses sample.csv file consisting of data that causes NaN issue. Filtering by favourableTop10 == "Unfavourable Top 10" causes the NaN but favourableTop10 == "Favourable Top 10" works.

I have also attached screenshots of the RStudio Viewer output for both filter cases.
Unfavourable Top 10
Favourable Top 10

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

No branches or pull requests

2 participants