Javascript R在应用程序之间建立链接
我有两个闪亮的应用程序,我想链接一个到另一个。其中一个有一个数据表,其中包含一些我想链接到另一个应用程序的值,我可以从Javascript R在应用程序之间建立链接,javascript,r,datatables,shiny,Javascript,R,Datatables,Shiny,我有两个闪亮的应用程序,我想链接一个到另一个。其中一个有一个数据表,其中包含一些我想链接到另一个应用程序的值,我可以从selectInput选项中选择该值 总而言之,我有一个应用程序看起来像这样(摘自): 库(闪亮) 图书馆(DT) 服务器修改我先前的响应(因为,同意,应该有一个更简单的解决方案) 相反,这里有一个基于挖掘会话对象的解决方案: 如果您通过打开第二个闪亮应用程序 (将server.com/app2更改为您的实际链接) 然后在第二个应用程序中,为选择对象包括以下内容: 编辑:注意,
selectInput
选项中选择该值
总而言之,我有一个应用程序看起来像这样(摘自):
库(闪亮)
图书馆(DT)
服务器修改我先前的响应(因为,同意,应该有一个更简单的解决方案)
相反,这里有一个基于挖掘会话对象的解决方案:
如果您通过打开第二个闪亮应用程序
(将server.com/app2更改为您的实际链接)
然后在第二个应用程序中,为选择对象包括以下内容:
编辑:注意,由于这依赖于会话对象,因此服务器功能将从功能(输入,输出)
更改为功能(输入,输出,会话)
ui.R:
服务器.R:
output$selectSpecies <- renderUI({
URLvars <- session$clientData$url_search
# NOTE: the following regex is not one-size-fits-all
# if you use multiple inputs, you'll probably need to adjust it
# also remove special characters, because I want to sanitize our inputs
Species <- gsub('[[:punct:]]','',URLvars)
Species <- sub('^.*Species(.*$)','\\1',URLvars)
selectInput("select", label=h3("Iris Type"), choices=list('setosa', 'versicolor', 'virginica'),
selected=ifelse(Species=="",'setosa',Species), multiple=FALSE)
})
output$selectSpecies这似乎非常接近您正在做的事情。可能很接近,但我不知道如何使用您链接中的答案解决我的问题。谢谢,它很有效!实际上,我不需要这一行:Species
library(shiny)
library(dplyr)
library(tidyr)
data(iris)
server <- shinyServer(function(input, output) {
iris1 <- reactive({
iris %>%
filter(Species %in% input$select)
})
output$filtered_data <- DT::renderDataTable({
datatable(iris1())
})
})
ui <- shinyUI(fluidPage(
mainPanel(
selectInput("select", label=h3("Iris Type"), choices=list('setosa', 'versicolor', 'virginica'),
selected='setosa', multiple=FALSE),
DT::dataTableOutput("filtered_data")
)
))
shinyApp(ui = ui, server = server)
htmlOutput('selectSpecies')
output$selectSpecies <- renderUI({
URLvars <- session$clientData$url_search
# NOTE: the following regex is not one-size-fits-all
# if you use multiple inputs, you'll probably need to adjust it
# also remove special characters, because I want to sanitize our inputs
Species <- gsub('[[:punct:]]','',URLvars)
Species <- sub('^.*Species(.*$)','\\1',URLvars)
selectInput("select", label=h3("Iris Type"), choices=list('setosa', 'versicolor', 'virginica'),
selected=ifelse(Species=="",'setosa',Species), multiple=FALSE)
})