我在试着连接一个按比例缩放的日志
noUiSliderInput
线性缩放
numericInput
通常,我会用以下命令停止更新行:
input$Histoslider != log10(input$Threshold_box)
这就产生了一些小数点的问题,我似乎无法解决。
详细说明:
我有一个应用程序,用户可以通过两种方式设置阈值过滤器:
数字输入
在未转换的数字中
2: 通过改变垂直方向上的条
努伊斯利德林普特
.
这个
努伊斯利德林普特
但是用log10数字表示,因为它与log10刻度的数据图排成一行。因此,如果绘图从10^1到10^4.5,则滑块的值从-1到4.5
数字输入
noUiSliderInputare
已链接,因此更改一个应更新另一个。
这给小数带来了很多困难。这个
在应用程序中必须限制为2位小数。为此,我添加了一些转换,舍入和转换再次得到匹配的数字。
我可以让它正常工作
sliderInput
但不知怎么的
努伊斯利德林普特
我必须坚持的原因
努伊斯利德林普特
是因为我需要在X和Y轴的情节滑块。
尝试在numericInput中键入1256以查看问题的示例
# 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)