Comments (6)
there are shiny observers on the slider that will give you the index of the current slide.
from slickr.
library(svglite)
library(lattice)
library(ggplot2)
library(shiny)
server <- function(input, output) {
output$distPlot <- renderSlickR({
slickR(s.in())
})
s.in=reactive({
sapply(
list(
xmlSVG({hist(rnorm(input$obs), col = 'darkgray', border = 'white')},standalone=TRUE)
,xmlSVG({print(xyplot(x~x,data.frame(x=1:10),type="l"))},standalone=TRUE)
,xmlSVG({show(ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,colour=Species))+geom_point())},standalone=TRUE)
,xmlSVG({
print(
dotplot(variety ~ yield | site , data = barley, groups = year,
key = simpleKey(levels(barley$year), space = "right"),
xlab = "Barley Yield (bushels/acre) ",
aspect=0.5, layout = c(1,6), ylab=NULL)
)
},standalone=TRUE
)
)
,function(sv){
paste0(
"data:image/svg+xml;utf8,"
,as.character(sv)
)
}
)
})
reactive_slide <- shiny::reactiveValues()
shiny::observeEvent(input$distPlot_current,{
current_slide <- input$distPlot_current$.clicked
if(!is.null(current_slide))
reactive_slide$current <- current_slide
})
output$results <- shiny::renderPrint({
str.out <- ''
if(length(reactive_slide$current)>0)
str.out=reactive_slide$current
return(str.out)
})
output$chosen <- shiny::renderUI({
list(shiny::h3('Selected Items'),
shiny::verbatimTextOutput(outputId = "results"))
})
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100),
shiny::uiOutput('chosen')
),
mainPanel(slickROutput("distPlot",width='200px',height='200px'))
)
)
shinyApp(ui = ui, server = server)
from slickr.
Thank you so much for the quick response, I really appreciate it.
Your code functions, but it's not quite what I was going for. I think I didn't explain my issue clearly. What I'm looking for is the ability to click on an image in the slider and be routed to a separate tab entirely. So each image has to have an ID associated with it that I can link to a different portion of the UI.
Maybe the index you mentioned can do that?
from slickr.
yes. build you tabs with id's that have indexes in them ie tab1,tab2,tab3... then in shiny do observeEvent on the current_index of the slider. within that update the active tab.
from slickr.
here is a working example
library(svglite)
library(lattice)
library(ggplot2)
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100),
shiny::uiOutput('chosen')
),
mainPanel(
slickROutput("distPlot",width='80%',height='200px'),
tabsetPanel(id = "inTabset",
tabPanel(title = "Panel 1", value = "panel1", "Panel 1 content"),
tabPanel(title = "Panel 2", value = "panel2", "Panel 2 content"),
tabPanel(title = "Panel 3", value = "panel3", "Panel 3 content"),
tabPanel(title = "Panel 4", value = "panel4", "Panel 4 content")
))
)
)
server <- function(input, output,session) {
output$distPlot <- renderSlickR({
slickR(s.in(),slickOpts = list(centerMode=TRUE,slidesToShow=2))
})
s.in=reactive({
sapply(
list(
xmlSVG({hist(rnorm(input$obs), col = 'darkgray', border = 'white')},standalone=TRUE)
,xmlSVG({print(xyplot(x~x,data.frame(x=1:10),type="l"))},standalone=TRUE)
,xmlSVG({show(ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,colour=Species))+geom_point())},standalone=TRUE)
,xmlSVG({
print(
dotplot(variety ~ yield | site , data = barley, groups = year,
key = simpleKey(levels(barley$year), space = "right"),
xlab = "Barley Yield (bushels/acre) ",
aspect=0.5, layout = c(1,6), ylab=NULL)
)
},standalone=TRUE
)
)
,function(sv){
paste0(
"data:image/svg+xml;utf8,"
,as.character(sv)
)
}
)
})
reactive_slide <- shiny::reactiveValues()
shiny::observeEvent(input$distPlot_current,{
current_slide <- input$distPlot_current$.clicked
relative_slide <- input$distPlot_current$.relative_clicked
center_slide <- input$distPlot_current$.center
total_slide <- input$distPlot_current$.total
id_slide <- input$distPlot_current$.slider_index
if(!is.null(current_slide))
reactive_slide$current <- current_slide
if(!is.null(relative_slide))
reactive_slide$relative <- relative_slide
if(!is.null(center_slide))
reactive_slide$center <- center_slide
if(!is.null(total_slide))
reactive_slide$total <- total_slide
if(!is.null(id_slide))
reactive_slide$id <- id_slide
})
output$results <- shiny::renderTable({
data.frame(SliderId=reactive_slide$id,
TotalSlides=reactive_slide$total,
CurrentSlide=reactive_slide$current,
RelativeSlide=reactive_slide$relative,
CenterSlide=reactive_slide$center)
})
output$chosen <- shiny::renderUI({
list(shiny::h3('Slider Info'),
shiny::tableOutput(outputId = "results"))
})
observeEvent(reactive_slide$current, {
updateTabsetPanel(session, "inTabset",
selected = paste0("panel", reactive_slide$current)
)
})
}
shinyApp(ui = ui, server = server)
from slickr.
Great, this works! Thank you so much, really appreciate it. I have one other question, but it's a different topic, so I'll open another case.
from slickr.
Related Issues (20)
- Error thrown by HTMLTools HOT 2
- slickR no longer available on CRAN HOT 2
- using slickR for mobile HOT 2
- slickR shiny vignette broken HOT 12
- shiny: Carousel "jumps" when re-rendered with numeric height HOT 3
- slickr_output_current$.center isn't providing data on shiny app startup HOT 3
- Synch 3 Carousels and Change Color of Text HOT 3
- Move previous next buttons HOT 4
- target = "_self" HOT 1
- Browser side linking to other chart HOT 4
- Replace a slide? HOT 1
- Shiny: carousel collapses / folds after clicking on different tab and returning to carousel page HOT 1
- SlickR always insert image into html
- Problem with slickR + shiny, when the xmlSVG-file becomes to large. HOT 2
- Change figure size according to browser window size
- SlickR and Shiny, duplicated carousels HOT 7
- how to continue the carousel after click the arrow? HOT 3
- Error in file.info(x, extra_cols = FALSE) : file name conversion problem -- name too long?
- How change style settings in multiple slider ?
- How does Slide Synchronization work with asNavFor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slickr.