Comments (7)
Hi @palderman, this feature has been on my to do list for a while now (#14) but I haven't had time to look at it further. I would be more than happy to review a PR to add improved support for validating data entries.
As discussed in #14 I think the col_options
argument would be a good place to add support for this. For example we could do something similar to the code below to restrict entries in vs
column of mtcars
to range [0,1]:
data_edit(
mtcars,
col_options = list(vs = c(0,1))
)
At the moment, the above code would trigger the vs
column to use a dropdown
menu with options 0
and 1
. This is because any vector passed to col_options
that doesn't contain either logical values or "date"
or "password"
character strings is treated as the options for data entry - so we resort to using dropdown columns to prevent typing errors. I do think there will be cases where users will want the above code to work as is, i.e. have numeric options in dropdown menus - so perhaps we should try to keep this functionality.
An alternative would be to add more flexibility to col_options
by allowing a list of arguments per column. For example, we could do something like this (vs
is the name of the column):
# numeric dropdown
data_edit(
mtcars,
col_options = list(
vs = list(
type = "dropdown",
options = c(0,1)
)
)
# numeric range
data_edit(
mtcars,
col_options = list(
vs = list(
range = c(0, 1),
precision = 0
)
)
In the above example each list could have options type
, options
, range
and precision
(and any other useful options).
type
controls the format for data entry (i.e. eitherpassword
,date
,checkbox
ordropdown
)options
indicates the available options for dropdown menusrange
allows specification of numeric ranges e.g.c(0,1)
. We may need to add another option likebounds
to indicate whether limits include upper and/or lower boundaries defined inrange
.precision
indicates the number of decimal places for rounding (integers could have precision zero for example)
Once we have a format for the new col_options
we need to make changes to the code in dataEdit.R
to make sure these options are appropriately handled. I think most of the changes will need to occur in this chunk of code which is triggered whenever the data changes (note that the column and row headers are handled separately in the chunk below).
Lines 260 to 286 in d2840dc
Basically all you would need to do to compare the columns defined in col_options
in the new data (x_new
) and make sure all the listed criteria are met - otherwise we replace that column with the previous version defined in x_old
. This method is not very efficient as you will be checking all entries not just the ones that have changed (remember this code is triggered with every single change - i.e. each time only a single value will be changed).
I think there is a way to check exactly which cell has been edited by accessing slots in input$x
but you will need to look at rhandsontable
to see how this works.
Hope this helps, happy to answer any questions you may have along the way.
Dillon
from dataeditr.
Sorry for missing #14. I should have checked the existing issues more thoroughly.
I was thinking of something along the lines you outlined above for an integer with hard min/max values:
# numeric dropdown
data_edit(
mtcars,
col_options = list(
vs = list(
type = "integer",
min = 0,
max = 10
)
)
Errant values in that case would be rejected, but I was also thinking of being able to warn about out-of-range values instead of rejecting them out right. In that case, supposing you have an integer that is usually between 3 and 5, but on rare occasions could possibly have values as low as 0 or high as 10, we could specify it as:
# numeric dropdown
data_edit(
mtcars,
col_options = list(
vs = list(
type = "integer",
range = c(0, 10),
range_warn = c(3, 5)
)
)
Values outside range
would be rejected and values outside range_warn
but inside range
could be highlighted in red or yellow. Thoughts?
from dataeditr.
Looks like a good starting point. I have played around with colouring cells and it is complicated.
For DataEditR to work, we need to set useTypes = FALSE
in rhandsontable()
which means we cannot make calls to hot_col()
or hot_cell()
to format the cells - this is because useTypes = FALSE
is required for the column/row addition/removal functionality.
Perhaps you will find a way to get this to work.
from dataeditr.
Dillon, I have a question.
I'm running DataEditR:: inside shiny as I need to validate multiple databases, however col_options() has a stop(!all(colnames %in% df)) if the columns are not contained in the dataframe. Do you have any suggestions, other than rewriting the function locally, on how to deal with this issue?
from dataeditr.
@BarqueRodrigues can you poibt me to exactly where that line exists in the code? I can take a look. Given that it is an error I probably put it there for a good reason.
from dataeditr.
Dillon in line 47 on DataEditR::dataEditServer
if (!is.null(col_readonly)) { if (!all(col_readonly %in% colnames(data_to_edit))) { stop("'col_readonly' must contain valid column names.") } values$col_names <- unique(c(col_names, col_readonly)) }
from dataeditr.
So you are using col_readonly
? In that case it must match the columns in the data. What is your use case? You have some code I can look at?
from dataeditr.
Related Issues (20)
- slow to update
- Data Not Saving HOT 3
- Error in shinytheme(theme): HOT 9
- yeti is not an available theme HOT 2
- type.convert turns in certain cases numerics to integer, so that only integers are allowed when editing HOT 4
- Calling process terminates 30ms after exiting from DataEditR HOT 2
- Different return value for cancel button HOT 2
- Print edited table in shiny app HOT 1
- Feature Request: Edit geospatial attributes HOT 1
- Feature Request: Add/Remove cell above/cell below
- Bad priority handler in dataEditServer HOT 6
- DataEditR does not return modified R object HOT 5
- Data table not showing data_edit
- dataEditServer - change of input dataset not working inside of modal
- DataEditR not synching on posit Cloud HOT 1
- Error in rep: (converted from warning) partial argument match of 'len' to 'length.out'
- data_edit crashes if the last column is selected
- Does "contains" / "not contains" filters really works? HOT 4
- Does DataEditR really works when using 3+ filters? HOT 1
- display cell as html
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dataeditr.