problem with noUiSliderInput output having only 2 decimals
I'm trying to link a log scaled noUiSliderInput
with a linear scaled numericInput
without creating an eternal update loop.
Normally I would stop the update lines with this:
input$Histoslider != log10(input$Threshold_box)
This created some issues with decimals, which I can't seem to fix properly.
The main problem seems to be that noUiSliderInput always rounds its output to 2 decimals, causing the rounding problem for the conversion to 10^ and log10 back and forth
Detailed description:
I have an app where the user can set threshold filters in 2 ways:
1: type the number in a numericInput
in un-transformed numbers
or
2: by changing the bar on a vertical noUiSliderInput
.
The noUiSliderInput
however is expressed as log10 numbers, as it is lined up with a plot of the data on log10 scale. so if the plot runs from 10^-1 to 10^4.5, the slider has values running from -1 to 4.5
The numericInput
and noUiSliderInputare
linked, so change one should update the other.
This created a lot of difficulty with decimals. The numericInput
has to be restricted in the app to 2 decimals. So to do that I add some transformation, rounding and transformation back again to get matching numbers.
I can get it to work for a normal sliderInput
, but somehow not for a noUiSliderInput
, eventhough they should spit out the same format of data.
The reason I have to stick with a noUiSliderInput
is because I need a slider on both the x and y axis of the plot.
Try to type 1256 in the numericInput to see an example of the problem
The app:
# install.packages("devtools")
devtools::install_github("dreamRs/shinyWidgets")
library(shiny)
library(shinyWidgets)
# function to see how many decimal places we need
decimalplaces <- function(x)
if ((x %% 1) != 0)
deci <- nchar(strsplit(sub('0+$', '', as.character(x)), ".", fixed=TRUE)[[1]][[2]])
if(deci >2) deci <- 2
return(deci)
else
return(0)
# starting values for the sliders
minval <- round(-1, digits = 6)
maxval <- round(4.5, digits = 6)
ui <- fluidPage(
tags$br(),
fluidRow(
column(3,
div(numericInput("Threshold_box", "Normal value: ", min = 0, max = 100, value = 1, step=0.01), style = "display:inline-block") ),
column(2,
# div(sliderInput( inputId = "Histoslider", label = NULL, min = minval, max = maxval, value = 0, step = 0.000001), style = 'display:inline-block; position:relative')
noUiSliderInput(inputId = "Histoslider", label = NULL, min = minval, max = maxval, tooltips = FALSE, value = 0, step = 0.000001, direction = "rtl", orientation = "vertical", width = "100px", height = "276px")
)))
server <- function(input, output, session)
#setting decimals to 6 as that seemed to work in the end for a normal sliderInput
values <- reactiveValues( transformDecimal = 2)
observeEvent(input$Threshold_box,
if(!is.na(input$Threshold_box)) values$transformDecimal <- decimalplaces(input$Threshold_box)
if(input$Histoslider != log10(input$Threshold_box))
newval <- log10(input$Threshold_box)
# updateSliderInput(session, 'Histoslider', value = newval)
updateNoUiSliderInput(session, 'Histoslider', value = newval)
, ignoreInit = T)
observeEvent(input$Histoslider,
## next three lines are to get matching set between a 2 decimal numer and the log value
sliderFull <- 10^input$Histoslider
sliderRound <- round(sliderFull, digits = values$transformDecimal)
sliderLog <- log10(sliderRound)
updateSliderInput(session, 'Histoslider', value = sliderLog)
if(sliderLog != log10(input$Threshold_box))
updateNumericInput(session, 'Threshold_box', value = round(10^sliderLog, digits = values$transformDecimal))
, ignoreInit = T)
shinyApp(ui, server)
r shiny decimal
add a comment |
I'm trying to link a log scaled noUiSliderInput
with a linear scaled numericInput
without creating an eternal update loop.
Normally I would stop the update lines with this:
input$Histoslider != log10(input$Threshold_box)
This created some issues with decimals, which I can't seem to fix properly.
The main problem seems to be that noUiSliderInput always rounds its output to 2 decimals, causing the rounding problem for the conversion to 10^ and log10 back and forth
Detailed description:
I have an app where the user can set threshold filters in 2 ways:
1: type the number in a numericInput
in un-transformed numbers
or
2: by changing the bar on a vertical noUiSliderInput
.
The noUiSliderInput
however is expressed as log10 numbers, as it is lined up with a plot of the data on log10 scale. so if the plot runs from 10^-1 to 10^4.5, the slider has values running from -1 to 4.5
The numericInput
and noUiSliderInputare
linked, so change one should update the other.
This created a lot of difficulty with decimals. The numericInput
has to be restricted in the app to 2 decimals. So to do that I add some transformation, rounding and transformation back again to get matching numbers.
I can get it to work for a normal sliderInput
, but somehow not for a noUiSliderInput
, eventhough they should spit out the same format of data.
The reason I have to stick with a noUiSliderInput
is because I need a slider on both the x and y axis of the plot.
Try to type 1256 in the numericInput to see an example of the problem
The app:
# install.packages("devtools")
devtools::install_github("dreamRs/shinyWidgets")
library(shiny)
library(shinyWidgets)
# function to see how many decimal places we need
decimalplaces <- function(x)
if ((x %% 1) != 0)
deci <- nchar(strsplit(sub('0+$', '', as.character(x)), ".", fixed=TRUE)[[1]][[2]])
if(deci >2) deci <- 2
return(deci)
else
return(0)
# starting values for the sliders
minval <- round(-1, digits = 6)
maxval <- round(4.5, digits = 6)
ui <- fluidPage(
tags$br(),
fluidRow(
column(3,
div(numericInput("Threshold_box", "Normal value: ", min = 0, max = 100, value = 1, step=0.01), style = "display:inline-block") ),
column(2,
# div(sliderInput( inputId = "Histoslider", label = NULL, min = minval, max = maxval, value = 0, step = 0.000001), style = 'display:inline-block; position:relative')
noUiSliderInput(inputId = "Histoslider", label = NULL, min = minval, max = maxval, tooltips = FALSE, value = 0, step = 0.000001, direction = "rtl", orientation = "vertical", width = "100px", height = "276px")
)))
server <- function(input, output, session)
#setting decimals to 6 as that seemed to work in the end for a normal sliderInput
values <- reactiveValues( transformDecimal = 2)
observeEvent(input$Threshold_box,
if(!is.na(input$Threshold_box)) values$transformDecimal <- decimalplaces(input$Threshold_box)
if(input$Histoslider != log10(input$Threshold_box))
newval <- log10(input$Threshold_box)
# updateSliderInput(session, 'Histoslider', value = newval)
updateNoUiSliderInput(session, 'Histoslider', value = newval)
, ignoreInit = T)
observeEvent(input$Histoslider,
## next three lines are to get matching set between a 2 decimal numer and the log value
sliderFull <- 10^input$Histoslider
sliderRound <- round(sliderFull, digits = values$transformDecimal)
sliderLog <- log10(sliderRound)
updateSliderInput(session, 'Histoslider', value = sliderLog)
if(sliderLog != log10(input$Threshold_box))
updateNumericInput(session, 'Threshold_box', value = round(10^sliderLog, digits = values$transformDecimal))
, ignoreInit = T)
shinyApp(ui, server)
r shiny decimal
add a comment |
I'm trying to link a log scaled noUiSliderInput
with a linear scaled numericInput
without creating an eternal update loop.
Normally I would stop the update lines with this:
input$Histoslider != log10(input$Threshold_box)
This created some issues with decimals, which I can't seem to fix properly.
The main problem seems to be that noUiSliderInput always rounds its output to 2 decimals, causing the rounding problem for the conversion to 10^ and log10 back and forth
Detailed description:
I have an app where the user can set threshold filters in 2 ways:
1: type the number in a numericInput
in un-transformed numbers
or
2: by changing the bar on a vertical noUiSliderInput
.
The noUiSliderInput
however is expressed as log10 numbers, as it is lined up with a plot of the data on log10 scale. so if the plot runs from 10^-1 to 10^4.5, the slider has values running from -1 to 4.5
The numericInput
and noUiSliderInputare
linked, so change one should update the other.
This created a lot of difficulty with decimals. The numericInput
has to be restricted in the app to 2 decimals. So to do that I add some transformation, rounding and transformation back again to get matching numbers.
I can get it to work for a normal sliderInput
, but somehow not for a noUiSliderInput
, eventhough they should spit out the same format of data.
The reason I have to stick with a noUiSliderInput
is because I need a slider on both the x and y axis of the plot.
Try to type 1256 in the numericInput to see an example of the problem
The app:
# install.packages("devtools")
devtools::install_github("dreamRs/shinyWidgets")
library(shiny)
library(shinyWidgets)
# function to see how many decimal places we need
decimalplaces <- function(x)
if ((x %% 1) != 0)
deci <- nchar(strsplit(sub('0+$', '', as.character(x)), ".", fixed=TRUE)[[1]][[2]])
if(deci >2) deci <- 2
return(deci)
else
return(0)
# starting values for the sliders
minval <- round(-1, digits = 6)
maxval <- round(4.5, digits = 6)
ui <- fluidPage(
tags$br(),
fluidRow(
column(3,
div(numericInput("Threshold_box", "Normal value: ", min = 0, max = 100, value = 1, step=0.01), style = "display:inline-block") ),
column(2,
# div(sliderInput( inputId = "Histoslider", label = NULL, min = minval, max = maxval, value = 0, step = 0.000001), style = 'display:inline-block; position:relative')
noUiSliderInput(inputId = "Histoslider", label = NULL, min = minval, max = maxval, tooltips = FALSE, value = 0, step = 0.000001, direction = "rtl", orientation = "vertical", width = "100px", height = "276px")
)))
server <- function(input, output, session)
#setting decimals to 6 as that seemed to work in the end for a normal sliderInput
values <- reactiveValues( transformDecimal = 2)
observeEvent(input$Threshold_box,
if(!is.na(input$Threshold_box)) values$transformDecimal <- decimalplaces(input$Threshold_box)
if(input$Histoslider != log10(input$Threshold_box))
newval <- log10(input$Threshold_box)
# updateSliderInput(session, 'Histoslider', value = newval)
updateNoUiSliderInput(session, 'Histoslider', value = newval)
, ignoreInit = T)
observeEvent(input$Histoslider,
## next three lines are to get matching set between a 2 decimal numer and the log value
sliderFull <- 10^input$Histoslider
sliderRound <- round(sliderFull, digits = values$transformDecimal)
sliderLog <- log10(sliderRound)
updateSliderInput(session, 'Histoslider', value = sliderLog)
if(sliderLog != log10(input$Threshold_box))
updateNumericInput(session, 'Threshold_box', value = round(10^sliderLog, digits = values$transformDecimal))
, ignoreInit = T)
shinyApp(ui, server)
r shiny decimal
I'm trying to link a log scaled noUiSliderInput
with a linear scaled numericInput
without creating an eternal update loop.
Normally I would stop the update lines with this:
input$Histoslider != log10(input$Threshold_box)
This created some issues with decimals, which I can't seem to fix properly.
The main problem seems to be that noUiSliderInput always rounds its output to 2 decimals, causing the rounding problem for the conversion to 10^ and log10 back and forth
Detailed description:
I have an app where the user can set threshold filters in 2 ways:
1: type the number in a numericInput
in un-transformed numbers
or
2: by changing the bar on a vertical noUiSliderInput
.
The noUiSliderInput
however is expressed as log10 numbers, as it is lined up with a plot of the data on log10 scale. so if the plot runs from 10^-1 to 10^4.5, the slider has values running from -1 to 4.5
The numericInput
and noUiSliderInputare
linked, so change one should update the other.
This created a lot of difficulty with decimals. The numericInput
has to be restricted in the app to 2 decimals. So to do that I add some transformation, rounding and transformation back again to get matching numbers.
I can get it to work for a normal sliderInput
, but somehow not for a noUiSliderInput
, eventhough they should spit out the same format of data.
The reason I have to stick with a noUiSliderInput
is because I need a slider on both the x and y axis of the plot.
Try to type 1256 in the numericInput to see an example of the problem
The app:
# install.packages("devtools")
devtools::install_github("dreamRs/shinyWidgets")
library(shiny)
library(shinyWidgets)
# function to see how many decimal places we need
decimalplaces <- function(x)
if ((x %% 1) != 0)
deci <- nchar(strsplit(sub('0+$', '', as.character(x)), ".", fixed=TRUE)[[1]][[2]])
if(deci >2) deci <- 2
return(deci)
else
return(0)
# starting values for the sliders
minval <- round(-1, digits = 6)
maxval <- round(4.5, digits = 6)
ui <- fluidPage(
tags$br(),
fluidRow(
column(3,
div(numericInput("Threshold_box", "Normal value: ", min = 0, max = 100, value = 1, step=0.01), style = "display:inline-block") ),
column(2,
# div(sliderInput( inputId = "Histoslider", label = NULL, min = minval, max = maxval, value = 0, step = 0.000001), style = 'display:inline-block; position:relative')
noUiSliderInput(inputId = "Histoslider", label = NULL, min = minval, max = maxval, tooltips = FALSE, value = 0, step = 0.000001, direction = "rtl", orientation = "vertical", width = "100px", height = "276px")
)))
server <- function(input, output, session)
#setting decimals to 6 as that seemed to work in the end for a normal sliderInput
values <- reactiveValues( transformDecimal = 2)
observeEvent(input$Threshold_box,
if(!is.na(input$Threshold_box)) values$transformDecimal <- decimalplaces(input$Threshold_box)
if(input$Histoslider != log10(input$Threshold_box))
newval <- log10(input$Threshold_box)
# updateSliderInput(session, 'Histoslider', value = newval)
updateNoUiSliderInput(session, 'Histoslider', value = newval)
, ignoreInit = T)
observeEvent(input$Histoslider,
## next three lines are to get matching set between a 2 decimal numer and the log value
sliderFull <- 10^input$Histoslider
sliderRound <- round(sliderFull, digits = values$transformDecimal)
sliderLog <- log10(sliderRound)
updateSliderInput(session, 'Histoslider', value = sliderLog)
if(sliderLog != log10(input$Threshold_box))
updateNumericInput(session, 'Threshold_box', value = round(10^sliderLog, digits = values$transformDecimal))
, ignoreInit = T)
shinyApp(ui, server)
r shiny decimal
r shiny decimal
edited Nov 10 '18 at 16:13
Mark
asked Nov 10 '18 at 15:12
MarkMark
529521
529521
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240290%2fproblem-with-nouisliderinput-output-having-only-2-decimals%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240290%2fproblem-with-nouisliderinput-output-having-only-2-decimals%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown