2017-09-04 8 views
0

光沢のあるUIで選択された入力に基づいてサブセットを実行するよりも、コードチャンクを実行するのが面倒です。光沢のあるユーザー情報に基づいてactionButtonでデータフレームをサブセット化する方法R

これを実行するには、私は別のアプローチを試してみましたが、運と:

私はUIでこのような何かをしたい:このような

ui = navbarPage(title = 'panel', 
      fluidPage(
       fluidRow(
       column(2, 
         selectInput('a', label = "choose", 
            choices = unique(df$a)), 
         sliderInput(
         'b', label = 'choose range:', 
         min = 5, max = 8, value = c(6,7)), 
         actionButton('click','click')), 
column(5, 
     tableOutput('table'))))) 

と何かをサーバー上

server = function(input,output){ 
        df= data.frame(a = c(1,2,3,4), b = c(5,6,7,8)) 

    observeEvent(input$click,{ 
       df_ = subset(df, 
       a == input$a & 
       b %in% input$b[1]:input$b[2]) 
       }) 

    input$table = renderDataTable({ 
    df_ 
    }) 
    } 

このコードを実行すると、このエラーになります。

shinyApp(ui, server) 

Warning: Error in $<-.reactivevalues: Attempted to assign value to a read- 
only reactivevalues object 
Stack trace (innermost first): 
47: $<-.reactivevalues 
46: $<- [#11] 
45: server [#11] 
4: <Anonymous> 
3: do.call 
2: print.shiny.appobj 
1: <Promise> 
Error in `$<-.reactivevalues`(`*tmp*`, "table", value = structure(function 
(...) : 
Attempted to assign value to a read-only reactivevalues object 

私は、反応性のある価値あるものをいくつか見逃していると思いますが、私は失明しています。私はRstudioによって提供されるもののような反応ボタンのいくつかの例を試してきましたが、運はありません。

答えて

0

はおそらく、我々は

fsel(df) 

アプリ-run

library(shiny) 
library(DT 
fsel <- function(dat) { 

ui = navbarPage(title = 'panel', 
       fluidPage(
        fluidRow(
        column(2, 
          selectInput('a', label = "choose", 
             choices = unique(dat$a), selected = unique(dat$a)[1]), 
          sliderInput(
          'b', label = 'choose range:', 
          min = 5, max = 8, value = c(6,7)), 
          actionButton('click','click')), 
        column(5, 
          DT::dataTableOutput('table'))))) 


server = function(input,output){ 


    rs <- reactiveValues() 


    rs$df <- dat 
    observeEvent(input$click,{ 
    df_ <- subset(dat, 
        a == input$a & 
        b %in% input$b[1]:input$b[2]) 
    rs$df <- df_ 
    }) 

    output$table = renderDataTable({ 

    DT::datatable(rs$df) 

    }) 
} 
shinyApp(ui = ui, server = server) 
} 

-data

df <- data.frame(a = sample(letters[1:3], 10, replace = TRUE), 
       b =1:10, stringsAsFactors = FALSE) 

input$tableoutput$tableに変更し、 'UI' でDT::dataTableOutput('table')を使用する必要があります - 出力 enter image description here

enter image description here

関連する問題