2017-11-16 1 views
7

Flexdashboard를 Shiny state 북마크와 결합하려고합니다. (워드 프로세서에서 예) 단독으로 사용하면 반짝 응용 프로그램은 잘 작동하지만 flexdasboard에 넣어 경우, URL이 업데이트되지 않습니다 :Flexdashboard가 Shiny URL 상태에서 작동하지 않습니다.

--- 
title: "Untitled" 
output: 
    flexdashboard::flex_dashboard: 
    orientation: columns 
    vertical_layout: fill 
    runtime: shiny 
--- 

```{r setup, include=FALSE} 
library(flexdashboard) 
``` 

Column {data-width=650} 
----------------------------------------------------------------------- 

### Chart A 

```{r} 

shinyApp(
    ui=function(req) { 
    fluidPage(
     textInput("txt", "Text"), 
     checkboxInput("chk", "Checkbox") 
    ) 
    }, 
    server=function(input, output, session) { 
    observe({ 
     # Trigger this observer every time an input changes 
     reactiveValuesToList(input) 
     session$doBookmark() 
    }) 
    onBookmarked(function(url) { 
     updateQueryString(url) 
    }) 
    }, 
    enableBookmarking = "url" 
) 

``` 

이도 가능합니까? 독립 실행 비교 : 그것은 onBookmarked (그리고 onBookmark, onRestoreonRestored 같은 유사한 사건)과 같은

shinyApp(
    ui=function(req) { 
    fluidPage(
     textInput("txt", "Text"), 
     checkboxInput("chk", "Checkbox") 
    ) 
    }, 
    server=function(input, output, session) { 
    observe({ 
     # Trigger this observer every time an input changes 
     reactiveValuesToList(input) 
     session$doBookmark() 
    }) 
    onBookmarked(function(url) { 
     updateQueryString(url) 
    }) 
    }, 
    enableBookmarking = "url" 
) 

트리거되지 않습니다.

답변

6

R Markdown 문서에 포함 된 Shiny 앱에서는 북마크가 지원되지 않습니다. 여기

참조 토론 : 그것은 기술적으로 가능하지만, 할 까다로운처럼 https://github.com/rstudio/shiny/pull/1209#issuecomment-227207713

는 소리. 예를 들어 문서에 여러 개의 앱이 포함되어 있으면 어떻게됩니까? 또한 앱은 iframe으로 삽입되므로 이러한 앱이 상위 창 URL에 액세스하거나 수정할 수 있도록하기 위해 일부 배선을해야합니다.


그러나 북마크는 전체 응용 프로그램이 아니라 내장 된 반짝이 구성 요소에서 작동합니다.

--- 
title: "Untitled" 
output: 
    flexdashboard::flex_dashboard: 
    orientation: columns 
    vertical_layout: fill 
runtime: shiny 
--- 

```{r setup, include=FALSE} 
knitr::opts_chunk$set(echo = FALSE) 
enableBookmarking("url") 
``` 

```{r, include=FALSE} 
observe({ 
    reactiveValuesToList(input) 
    session$doBookmark() 
}) 

onBookmarked(function(url) { 
    updateQueryString(url) 
}) 

output$content <- renderUI({ 
    tagList(
    textInput("txt", "Text"), 
    checkboxInput("chk", "Checkbox") 
) 
}) 
``` 

Column {data-width=650} 
----------------------------------------------------------------------- 

### Chart A 

```{r} 
fluidPage(
    uiOutput("content"), 
    selectInput("sel", label = "Select", choices = c(10, 20, 30), selected = 10) 
) 
``` 

북마크가 UI 이후 같은 100 % 작동하지 않을 것입니다하지만 당신은 또한, Prerendered Shiny Documents 사용할 수는 미리 렌더링입니다. 정적 UI는 bookmarking callbacks으로 수동 복원해야하지만 동적 UI는 정상적으로 복원됩니다.

--- 
title: "Untitled" 
output: 
    flexdashboard::flex_dashboard: 
    orientation: columns 
    vertical_layout: fill 
runtime: shiny_prerendered 
--- 

```{r setup, include=FALSE} 
knitr::opts_chunk$set(echo = FALSE) 
enableBookmarking("url") 
``` 

```{r, context="server"} 
observe({ 
    reactiveValuesToList(input) 
    session$doBookmark() 
}) 

onBookmarked(function(url) { 
    updateQueryString(url) 
}) 

# Static inputs are pre-rendered, and must be manually restored 
onRestored(function(state) { 
    updateSelectInput(session, "sel", selected = state$input$sel) 
}) 

# Dynamic inputs will be restored with no extra effort 
output$content <- renderUI({ 
    tagList(
    textInput("txt", "Text"), 
    checkboxInput("chk", "Checkbox") 
) 
}) 
``` 

Column {data-width=650} 
----------------------------------------------------------------------- 

### Chart A 

```{r} 
fluidPage(
    uiOutput("content"), 
    selectInput("sel", label = "Select", choices = c(10, 20, 30), selected = 10) 
) 
``` 
관련 문제