Comments (4)
I can't get your example to run, I think it is a problem with the DT
package. I've never used it before. But I think you would want to do something like this:
library("shiny")
library("shinydashboard")
library("datasets")
library("DT")
library("shinyBS")
header <- dashboardHeader()
sidebar <- dashboardSidebar()
body <- dashboardBody(
DT::dataTableOutput("mtcarsTable"),
bsModal("mtCarsModal", "My Modal", "", tags$p("Hello World"), size = "small")
)
shinyApp(
ui = dashboardPage(header, sidebar, body),
server = function(input, output, session) {
mtcarsLinked <- reactive({
mtcars$mpg <- sapply(datasets::mtcars$mpg, function(x) {as.character(tags$a(href = "#", onclick = "$('#mtCarsModal').modal('show')", x))})
print(class(mtcars))
return(mtcars)
})
output$mtcarsTable <- DT::renderDataTable({
return(DT::datatable(mtcars,
class = 'compact',
escape = FALSE
))
})
}
)
Like I said, I can't get your example to actually run so this exact example might not work but something along these lines should. To have different data depending on what is clicked you would have to have extra javascript in your onclick event to update the innerHTML of $("#mtCarsModal .modal-body"), create separate modals for each link, or create a hidden input that updates on clicking a link and is attached to the server. Then have observers on the server watch for changes in that hidden input. (Use toggleModal()
in the observer to open the modal)
Hope this helps,
Eric
from shinybs.
Thanks for the swift response Eric.
I had to edit your code slightly, but I have it working.
library("shiny")
library("shinydashboard")
library("datasets")
library("DT")
library("shinyBS")
header <- dashboardHeader()
sidebar <- dashboardSidebar()
body <- dashboardBody(
DT::dataTableOutput("mtcarsTable"),
bsModal("mtCarsModal", "My Modal", "",tags$p("Hello World"), size = "small")
)
shinyApp(
ui = dashboardPage(header, sidebar, body),
server = function(input, output, session) {
mtcarsLinked <- reactive({
mtcars$mpg <- sapply(datasets::mtcars$mpg, function(x) {as.character(tags$a(href = "#", onclick = "$('#mtCarsModal').modal('show')", x))})
return(mtcars)
})
output$mtcarsTable <- DT::renderDataTable({
DT::datatable(mtcarsLinked(),
class = 'compact',
escape = FALSE
)
})
}
)
Next step is dynamic modal-body content based on the item selected.
Thanks for your help.
from shinybs.
@phillc73 Did you ever proceed with the next step?
I would love to have an example how to do dynamic modal based on the item clicked. Thanks
from shinybs.
Wow I figured it out. Here is an example if someone else winds up here.
Let me know if there is a better way.
library("shiny")
library("datasets")
library("DT")
library("shinyBS")
ui = shinyUI(fluidPage(
DT::dataTableOutput("mtcarsTable"),
bsModal("mtCarsModal", "My Modal", "",textOutput('mytext'), size = "small")
))
on_click_js = "
Shiny.onInputChange('mydata', '%s');
$('#mtCarsModal').modal('show')
"
convert_to_link = function(x) {
as.character(tags$a(href = "#", onclick = sprintf(on_click_js,x), x))
}
shinyApp(
ui = ui,
server = function(input, output, session) {
mtcarsLinked <- reactive({
mtcars$mpg <- sapply(
datasets::mtcars$mpg,convert_to_link)
return(mtcars)
})
output$mtcarsTable <- DT::renderDataTable({
DT::datatable(mtcarsLinked(),
class = 'compact',
escape = FALSE, selection='none'
)
})
output$mytext = renderText(sprintf('mpg value is %s',input$mydata))
}
)
source: https://ryouready.wordpress.com/2013/11/20/sending-data-from-client-to-server-and-back-using-shiny/
from shinybs.
Related Issues (20)
- Fast clicks can cause issues with bsModal
- Jquery error Uncaught Error: Syntax error, unrecognized expression: # HOT 2
- Mt app is frozen when close two opened modals
- FR: Allow updating additional attributes in `updatePanel`
- FR: Allow specification of id tag in bsCollapsePanel
- FR: Add 'multiple' parameter to `collapseUpdate`
- Uncaught referenceErrorL ShinyBS is not defined at ..... HOT 4
- Soft wrap long text in bsCollapsePanel()
- Is someone taking over support of this package?
- Change the way shinyBS adds resource path HOT 1
- modal is not working in ioslides_presentation
- Tooltips does not show up with shinyDashboard boxes sidebar
- bsModal works with shinydashboard but not when tabItems / tabItem are utilized HOT 2
- Dependencies failed to load HOT 1
- Alternatives to shinyBS HOT 2
- bsPopover (tooltip) not working in shinyapps.io
- feature request, load function HOT 1
- createAlert styles
- bsTooltip broken for selectizeInput and selectInput(..., multiple = T) HOT 1
- Lazy loading
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 shinybs.