2017-10-04 1 views
0

DTに埋め込むダイアログがあるため、サーバー側で作成する必要があるダイアログがあります。光沢のあるuiOutputサーバー側から取得した値を取得する方法

observeEvent(input$show, { 
    showModal(modalDialog(
     title = "Select location:", 
     uiOutput('select.file'), 

     # plotOutput("plot"), 
     easyClose = TRUE 
    )) 
}) 

、私は次のようにダイアログの行を埋め込む:

newrow <- shinyInput(actionButton, 5, 'button_', label = "Season", onclick = 'Shiny.onInputChange(\"show\", this.id)') 

問題があることである、私は私のダイアログで、次のを持っているので

私はこの質問を作成する理由は、ユーザーにデータの表示方法を示すプロットをしたいときは、これまでに選択した値がわからないためにできません。このため、私はCSVとしてそれを読んでプロットすることはできません。

誰かが私にアプローチまたはアイデアを提供できますか?私はまったく新鮮です。 ありがとう、

答えて

1

クリックするとグラフが生成される場所の下の例をご覧ください。

ここでは、選択した行を反応番号SelectedRow()にラップして、行番号に対してマップすることができます。私はmodalタイトルに行番号を表示しています

rm(list = ls()) 
library(DT) 
library(shiny) 
library(shinyBS) 

# This function will create the buttons for the datatable, they will be unique 
shinyInput <- function(FUN, len, id, ...) {inputs <- character(len) 
for (i in seq_len(len)) { 
    inputs[i] <- as.character(FUN(paste0(id, i), ...))} 
inputs 
} 


ui <- fluidPage(
    DT::dataTableOutput('my_table'),uiOutput("popup") 
) 

server <- function(input, output, session) { 
    my_data <- reactive({ 
    testdata <- mtcars 
    as.data.frame(cbind(View = shinyInput(actionButton, nrow(testdata),'button_', label = "View", onclick = 'Shiny.onInputChange(\"select_button\", this.id)'),testdata)) 
    }) 
    output$my_table <- DT::renderDataTable(my_data(),selection = 'single',options = list(searching = FALSE,pageLength = 10),server = FALSE, escape = FALSE,rownames= FALSE) 

    SelectedRow <- eventReactive(input$select_button,{ 
    as.numeric(strsplit(input$select_button, "_")[[1]][2]) 
    }) 

    observeEvent(input$select_button, { 
    toggleModal(session, "modalExample", "open") 
    }) 

    DataRow <- eventReactive(input$select_button,{ 
    my_data()[SelectedRow(),2:ncol(my_data())] 
    }) 

    output$popup <- renderUI({ 
    bsModal("modalExample", paste0("Data for Row Number: ",SelectedRow()), "", size = "large", 
      column(12,renderPlot(plot(mtcars))    
      ) 
    ) 
    }) 
} 

shinyApp(ui, server) 

enter image description here

関連する問題