全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1114 0
2019-07-24
最近在研究路径分析,做了一个交互界面,但是需要通过正则来选择相应的行,请教一下应该怎么在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)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群