我已经找到了一些关于如何改变valuea sliderInput中的反应式表达式的信息siderbarPanel.但是,而不是value,我想用一个改变min和max滑块numericInput.在这个脚本中server.R它表示只有label并且value可以更改为滑块.是否还有其他可能sliderInput通过反应式表达式更改最小值/最大值?
这是一个例子:
ui.R:
shinyUI(pageWithSidebar(
#Sidebar with controls to select the variable to plot
sidebarPanel(
#Numeric Inputs
numericInput("min_val", "Enter Minimum Value", 1993),
numericInput("max_val", "Enter Maximum Value", 2013),
#Slider
sliderInput("inSlider", "Slider",
min=1993, max=2013, value=2000),
# Now I would like to change min and max from sliderInput by changing the numericInput.
mainPanel()
))
Run Code Online (Sandbox Code Playgroud)
server.R:
library(shiny)
shinyServer(function(input, output, …Run Code Online (Sandbox Code Playgroud) 关于conditionalPanelR shiny 有很多问题,但我仍然不明白如何使用server.R创建的值conditionalPanel.这是我想要做的:我有一个像http://some-url.com/php/session_check.php?sid=session_id这样的网址.当session_id以0开头时,如http://some-url.com/php/session_check.php?sid=00221245,返回带有用户名的字符串(例如'testuser').当session_id以除0之外的任何其他数字开头时,例如http://some-url.com/php/session_check.php?sid=10221245,返回0.现在我想隐藏一个面板,具体取决于是返回0还是用户名.因此我尝试做这样的事情:
conditionalPanel(
condition="output.disable_ui!=0"
Run Code Online (Sandbox Code Playgroud)
我知道这是错误的,但我真的不知道该怎么办condition的说法工程outputs,就好像我会做到这一点对任何一样会工作input的ui.R.
这是我的示例代码:
server.R
library(shiny)
library(raster)
library(rgdal)
shinyServer(function(input, output, clientData) {
output$disable_ui<-reactive({
query<-parseQueryString(clientData$url_search)
url_path<-paste(sep="","http://some-url.com/php/session_check.php?sid=",query, collapse="")
read.table(url_path)
})
data <- reactive({
inFile <- input$example_layer
if (is.null(inFile))
return(NULL)
raster.file<- raster(inFile$datapath)
})
output$raster.plot <- renderPrint({
"Nothing to see here"
})
})
Run Code Online (Sandbox Code Playgroud)
ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("test"),
sidebarPanel(
conditionalPanel(
condition="output.disable_ui!=0",
#File Upload
fileInput('example_layer', 'Choose Raster Layer (ASCII)', multiple=FALSE, accept='asc')
)),
mainPanel( …Run Code Online (Sandbox Code Playgroud) 我想在反应式表达式中调用某个变量.像这样的东西:
server.R
library(raster)
shinyServer(function(input, output) {
data <- reactive({
inFile <- input$test #Some uploaded ASCII file
asc <- raster(inFile$datapath) #Reads in the ASCII as raster layer
#Some calculations with 'asc':
asc_new1 <- 1/asc
asc_new2 <- asc * 100
})
output$Plot <- renderPlot({
inFile <- input$test
if (is.null(inFile)
return (plot(data()$asc_new1)) #here I want to call asc_new1
plot(data()$asc_new2)) #here I want to call asc_new2
})
})
Run Code Online (Sandbox Code Playgroud)
不幸的是我无法找到如何打电话asc_new1和asc_new2内部data().这个不起作用:
data()$asc_new1
Run Code Online (Sandbox Code Playgroud) 我有一个data.frame> 100列,在导入它们之后都被格式化为数字.我想将特定列从数字转换为因子.我不想手动转换每一列,而是使用正则表达式为列名选择相关列并对其进行转换.在regexr.com的帮助下,我创建了以下表达式:\b\w{2,4}[1-9]\b.它应该选择列名称为2到4个字母的单词的所有列,以1到9的数字结尾.
这是一个例子:
df<-data.frame(pre1=c(1:10),
em2=c(1:10),
foo=c(1:10))
df
pre1 em2 foo
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
7 7 7 7
8 8 8 8
9 9 9 9
10 10 10 10
df %>%
select(matches("/\b\w{2,4]}[1-9]\b/"))
Error: '\w' is an unrecognized escape in character string starting ""/\b\w"
Run Code Online (Sandbox Code Playgroud)
这应该选择前两列,而不是第三列.似乎\w没有得到承认matches.还有其他办法吗?