2017-10-12 5 views
1

私のShinyアプリケーションのユーザーは、行と列の名前を持つ2x2テーブルの値を入力してもらいたいです。もちろん、私は4つの入力ボックスでそれを行うことができますが、すべてをきれいに配置するのは難しいと思います。それにもかかわらず、私はDTパッケージによって提供されるようなテーブルレイアウトを好むでしょう。したがって、私の質問です:datatable(または類似のもの)をユーザーが埋め込むことは可能ですか?テーブルをシャイニーに入れる方法は?

答えて

1

DTと解決策:

library(DT) 
library(shiny) 

dat <- data.frame(
    V1 = c(as.character(numericInput("x11", "", 0)), as.character(numericInput("x21", "", 0))), 
    V2 = c(as.character(numericInput("x21", "", 0)), as.character(numericInput("x22", "", 0))) 
) 

ui <- fluidPage(
    fluidRow(
    column(5, DT::dataTableOutput('my_table')), 
    column(2), 
    column(5, verbatimTextOutput("test")) 
) 
) 

server <- function(input, output, session) { 

    output$my_table <- DT::renderDataTable(
    dat, selection = "none", 
    options = list(searching = FALSE, paging=FALSE, ordering=FALSE, dom="t"), 
    server = FALSE, escape = FALSE, rownames= FALSE, colnames=c("", ""), 
    callback = JS("table.rows().every(function(i, tab, row) { 
        var $this = $(this.node()); 
        $this.attr('id', this.data()[0]); 
        $this.addClass('shiny-input-container'); 
        }); 
        Shiny.unbindAll(table.table().node()); 
        Shiny.bindAll(table.table().node());") 
) 

    output$test <- renderText({ 
    as.character(input$x11) 
    }) 

} 

shinyApp(ui, server) 
2

あなたがやりたいshinysky

devtools::install_github("AnalytixWare/ShinySky")パッケージ

またはrhandsontable使用することができます。

rm(list = ls()) 
library(shiny) 
library(shinysky) 

server <- shinyServer(function(input, output, session) { 

    # Initiate your table 
    previous <- reactive({mtcars[1:10,]}) 

    MyChanges <- reactive({ 
    if(is.null(input$hotable1)){return(previous())} 
    else if(!identical(previous(),input$hotable1)){ 
     # hot.to.df function will convert your updated table into the dataframe 
     as.data.frame(hot.to.df(input$hotable1)) 
    } 
    }) 
    output$hotable1 <- renderHotable({MyChanges()}, readOnly = F) 
    output$tbl = DT::renderDataTable(MyChanges()) 
}) 

ui <- basicPage(mainPanel(column(6,hotable("hotable1")),column(6,DT::dataTableOutput('tbl')))) 
shinyApp(ui, server) 

enter image description here

+0

'shinysky'パッケージはどこにありますか? 'install.packages(" shinysky ")'はそれが見つからないと言っています。 – Joe

+1

'devtools :: install_github(" AnalytixWare/ShinySky ")' –

関連する問題