最近在研究路径分析,做了一个交互界面,但是需要通过正则来选择相应的行,请教一下应该怎么在shiny中实现。以下是本人代码,但是正则表达式是个变量,不加引号报错,加了引号会按照字符串处理,求教
library(shiny)
library(sunburstR)
library(dplyr)
library(sunburstR)
sequence <- read.csv(
system.file('examples/visit-sequences.csv',
package = 'sunburstR'),
header = F,stringsAsFactors = F)
ui<-fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput('fre',
'Number of fre',
100,10000,1000),
selectInput('begin','begin action',
choices = c('account','home','product',
'end','search','other')),
selectInput('end','end action',
choices = c('account','home','product',
'end','search','other')),
actionButton('update','Update View')
),
mainPanel(
sunburstOutput("sunburst"),
textOutput("selection")
)
)
)
server <- function(input,output,session){
output$sunburst <- renderSunburst({
sequence = sequence[sequence$V2 > input$fre,]
res = str_extract(sequence[,1],input$begin.*input$end)
sequence$V1 = res
sequence = sequence[-which(is.na(sequence)),]
add_shiny(sunburst(sequence,count = TRUE))
})
selection <- reactive({
input$sunburst_mouseover
})
output$selection <- renderText(selection())
}
shinyApp(ui = ui, server = server)