Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 根据数据表设置更新输入_R_Shiny_Dt - Fatal编程技术网

R 根据数据表设置更新输入

R 根据数据表设置更新输入,r,shiny,dt,R,Shiny,Dt,我在一个闪亮的应用程序中有一个传单地图和数据表,并有各种输入框来选择要映射的内容 目前,数据在服务器上基于一组闪亮的输入进行处理,并且该数据被传递到传单和数据表。 我还希望在datatable上有一个按钮(或者读取datatable上的双击),并根据用户与datatable的交互来更新闪亮的输入(即调用shinny::updateSelectizeInput) 最小代码示例: if(交互式()){ 图书馆(闪亮) 图书馆(DT) shinyApp( ui=fluidPage( 选择输入(“种类选

我在一个闪亮的应用程序中有一个传单地图和数据表,并有各种输入框来选择要映射的内容

目前,数据在服务器上基于一组闪亮的输入进行处理,并且该数据被传递到传单和数据表。 我还希望在datatable上有一个按钮(或者读取datatable上的双击),并根据用户与datatable的交互来更新闪亮的输入(即调用
shinny::updateSelectizeInput

最小代码示例:

if(交互式()){
图书馆(闪亮)
图书馆(DT)
shinyApp(
ui=fluidPage(
选择输入(“种类选择”,“选择种类”,
choices=c(“全部”,如.character(iris$Species)))
,dataTableOutput(“dt”)
)
,服务器=功能(输入,输出){

输出$dt当然,但有点复杂。我使用mtcars,因为它有更多的种类:



库(闪亮)
图书馆(DT)
shinyApp(
#用户界面
用户界面
library(shiny)
library(DT)


shinyApp(

    #UI
    ui <- fluidPage(

        selectInput('carb_selection', 'Select carb', choices = c('all', as.character(mtcars$carb))),
        DT::dataTableOutput('dt'),

    ),

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

        #Function to create buttons
        shinyInput <- function(FUN, len, id, ...) {

            inputs <- character(len)
            for (i in seq_len(len)) {
                inputs[i] <- as.character(FUN(paste0(id, i), ...))
            }
            inputs

        }

        #Add buttons to the mtcars dataframe
        mtcars_btn <- reactiveValues(

            data = data.frame(

                mtcars,
                carb_selector = shinyInput(actionButton, nrow(mtcars), 'button_', label = "Select", onclick = 'Shiny.onInputChange(\"select_button\", this.id)'),
                stringsAsFactors = FALSE

            )

        )

        #Output datatable
        output$dt <- DT::renderDataTable(

            if (input$carb_selection == 'all'){

                DT::datatable(mtcars_btn$data, escape = FALSE, selection = 'none', options = list(searching = FALSE, ordering  = FALSE))

            } else {

                DT::datatable(mtcars_btn$data[mtcars_btn$data$carb == input$carb_selection, ], escape = FALSE, selection = 'none', options = list(searching = FALSE, ordering  = FALSE))

            }

        )

        #Observe a button being clicked
        observeEvent(input$select_button, {

            carb_selected <- mtcars_btn$data[as.numeric(strsplit(input$select_button, "_")[[1]][2]),]$carb

            print(paste0('clicked on ', carb_selected))

            updateSelectInput(session, 'carb_selection', selected = carb_selected)

        })

    }

)